我已经设置了一个windows azure网站(php),我想连接到azure存储(blob)环境。我浏览了How to use the Blob service from PHP教程,但只提到网站存储在本地时的情况。
我试图设置几个案例,但我经常遇到http 500错误。
<?php
require_once 'WindowsAzure/WindowsAzure.php';
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;
//$connectionString = "\WindowsAzure\Blob\Internal\IBlob";
// Create blob REST proxy.
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString); // the code gets stuck at this line, result is a HTTP 500 error
$content = fopen("C:\Users\Public\Pictures\Sample%20Pictures\Woestijn.jpg", "r");
$blob_name = "newBlob";
try {
//Upload blob
$blobRestProxy->createBlockBlob("default", $blob_name, $content);
}
catch(ServiceException $e){
// Handle exception based on error codes and messages.
// Error codes and messages are here:
// http://msdn.microsoft.com/en-us/library/windowsazure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}?>
是否有人遇到类似问题并设法解决问题?
编辑:
我现在缩小了错误搜索范围。我进入了ServicesBuilder.php文件,并逐行注释掉,直到页面停止工作。它出错的行是 $ httpClient ,如下所示:
public function createBlobService($connectionString)
{
$settings = StorageServiceSettings::createFromConnectionString(
$connectionString
);
$httpClient = $this->httpClient();
$serializer = $this->serializer();
$uri = Utilities::tryAddUrlScheme(
$settings->getBlobEndpointUri()
);
答案 0 :(得分:3)
从我所看到的你用$connectionString
填充"\WindowsAzure\Blob\Internal\IBlob"
变量:$connectionString = "DefaultEndpointsProtocol=https;AccountName=jeroensaccount;AccountKey=fjmezfjmIOFJEZIOPAFJAZOPIFJAIMO"
(即使它已被评论 - 所以可能你从其他地方传递它)。如果是这种情况,您需要更改它。
连接字符串应该是对包含协议,帐户名称和密钥的存储帐户的引用(您可以在门户中找到名称和密钥):
{{1}}