使用php通过azure网站连接到azure blob
我已经建立了一个WindowsAzure网站(php),我想连接到azure存储(blob)环境。我浏览了教程,但只提到了网站存储在本地的情况 我试着设置了一些案例,但我经常遇到http 500错误使用php通过azure网站连接到azure blob,php,azure,azure-storage,Php,Azure,Azure Storage,我已经建立了一个WindowsAzure网站(php),我想连接到azure存储(blob)环境。我浏览了教程,但只提到了网站存储在本地的情况 我试着设置了一些案例,但我经常遇到http 500错误 <?php require_once 'WindowsAzure/WindowsAzure.php'; use WindowsAzure\Common\ServicesBuilder; use WindowsAzure\Common\ServiceException; //$conn
<?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 />";
}?>
从我看到的情况来看,您正在使用以下值填充
$connectionString
变量:“\WindowsAzure\Blob\Internal\IBlob”
(即使它已注释-因此可能是从其他地方传递的)。如果是这样的话,你需要改变它
连接字符串应该是对存储帐户的引用,其中包含协议、帐户名称和密钥(您可以在门户中找到名称和密钥):
您不需要在帖子中包含签名-您的用户卡将自动添加。阅读了解更多详细信息。为什么您的
$connectionString
变量被注释掉了?另外,检查Sandrino的建议。connectionString被注释掉了,因为我在那里做的事情不起作用:)。Sandrino建议的连接字符串看起来像我需要的,但仍然不起作用。谢谢你的回复。据我所见,这应该更有意义,但我仍然得到http 500错误。希望您看到其他可能导致问题的原因。感谢您迄今为止的帮助。嗨,Sandrino,我缩小了搜索范围,找到了一个$httpClient变量,它给出了错误。我编辑了我的帖子,希望你能在里面找到有用的东西。
public function createBlobService($connectionString)
{
$settings = StorageServiceSettings::createFromConnectionString(
$connectionString
);
$httpClient = $this->httpClient();
$serializer = $this->serializer();
$uri = Utilities::tryAddUrlScheme(
$settings->getBlobEndpointUri()
);
$connectionString = "DefaultEndpointsProtocol=https;AccountName=jeroensaccount;AccountKey=fjmezfjmIOFJEZIOPAFJAZOPIFJAIMO"