【问题标题】:Connect to azure-blob through azure-website with php使用 php 通过 azure-website 连接到 azure-blob
【发布时间】: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


【解决方案1】:

据我所见,您正在使用以下值填充 $connectionString 变量:"\WindowsAzure\Blob\Internal\IBlob"(即使它已被注释 - 所以您可能是从其他地方传递它)。如果是这种情况,您需要更改它。

连接字符串应该是对您的存储帐户的引用,其中包含协议、帐户名称和密钥(您可以在门户中找到名称和密钥):

$connectionString = "DefaultEndpointsProtocol=https;AccountName=jeroensaccount;AccountKey=fjmezfjmIOFJEZIOPAFJAZOPIFJAIMO"

【讨论】:

  • 感谢您的回复。据我所知,这应该更有意义,但我仍然收到 http 500 错误。希望您看到其他可能导致问题的东西。感谢您迄今为止的帮助。
  • 嗨 Sandrino,我缩小了搜索范围,找到了一个 $httpClient 变量,它给出了错误。我编辑了我的帖子,希望你能从中找到有用的东西。
猜你喜欢
  • 2016-02-18
  • 2022-08-03
  • 1970-01-01
  • 1970-01-01
  • 2019-12-14
  • 1970-01-01
  • 1970-01-01
  • 2014-04-11
  • 1970-01-01
相关资源
最近更新 更多