【发布时间】:2012-12-05 12:51:36
【问题描述】:
我已经建立了一个 windows azure 网站 (php),我想连接到 azure storage (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()
);
【问题讨论】:
-
您不需要在帖子中包含签名 - 您的用户卡会自动添加。阅读FAQ了解更多详情。
-
为什么你的
$connectionString变量被注释掉了?另外,请查看 Sandrino 的建议。 -
connectionString 被注释掉,因为我在那里所做的没有工作:)。桑德里诺建议的 connectionString 看起来像我需要的,但仍然无法正常工作。
标签: php azure azure-storage