3
votes

I am running this code

require_once 'windowsazure\windowsazure.php';

use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\PublicAccessType;
use WindowsAzure\Common\ServiceException;

try {

$connectionString = "DefaultEndpointsProtocol=http;AccountName=xxx;AccountKey=yyyy";

// Create blob REST proxy.
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);

$createContainerOptions = new CreateContainerOptions();

$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);


// Set container metadata
$createContainerOptions->addMetaData("key1", "value1");
$createContainerOptions->addMetaData("key2", "value2");

// List blobs.
$blob_list = $blobRestProxy->listBlobs("mycontainer");
$blobs = $blob_list->getBlobs();

foreach($blobs as $blob)
{
    echo $blob->getName().": ".$blob->getUrl()."<br />";
}

// Create container.
$blobRestProxy->createContainer("phpcontainer", $createContainerOptions);

}
catch(ServiceException $e) {
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code . ": " . $error_message . "<br/>";
}

However, it will report the following error

ServiceException encountered. 400: Fail: Code: 400 Value: One of the request inputs is out of range. details (if any): OutOfRangeInputOne of the request inputs is out of range. RequestId:xxxxxx Time:2015-05-13T08:47:18.0943278Z

when it came to the first line of sending request to Azure storage

$blob_list = $blobRestProxy->listBlobs("mycontainer");

I've installed the dependency of Azure PHP SDK via pear (http_request2, mail_mime, mail_mimedecode) and put them at default position c:\php\pear\

And the connectionstring I used should be a correct one.

What I have missed?

Thanks

2
Where exactly in your code are you encountering the error?Gaurav Mantri
This line $blob_list = $blobRestProxy->listBlobs("mycontainer");Max Y

2 Answers

10
votes

It turns out that I wrongly specify an illegal account name in the connection string that I masked here, to be more specific, I use upper case in the account name but actually Azure container name is not allowed to contain Upper case, and my PHP project has not added the upper case to lower case transformation method...

Anyway, hoping anyone who has confronted similar problems may check the account name, container name and blob name firstly.

Thanks