代码之家  ›  专栏  ›  技术社区  ›  vasanths294

在Azure中创建blob时面临的问题

  •  1
  • vasanths294  · 技术社区  · 8 年前

    如何使用PHP在Microsoft Azure中的容器中创建blob。 遵循中的步骤 this link

    但仍面临一些问题。PHP代码未执行。 如何将文件或目录推送到现有blob中?

    <?php
    require_once 'vendor/autoload.php';
    
    use MicrosoftAzure\Storage\Common\ServicesBuilder;
    use MicrosoftAzure\Storage\Common\ServiceException;
    
    $connectionString = "DefaultEndpointsProtocol=https://sen123.blob.core.windows.net/srs123/sen123;AccountName=sen@gmail.com;AccountKey= ";
    
    // Create blob REST proxy.
    $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
    
    $content = fopen("D:\home\site\wwwroot\blobfile.txt", "r");
    $blob_name = "sen123";
    
    try    {
    //Upload blob
    $blobRestProxy->createBlockBlob("mycontainer", $blob_name, $content);
    }
    catch(ServiceException $e){
    // Handle exception based on error codes and messages.
    // Error codes and messages are here:
    // http://msdn.microsoft.com/library/azure/dd179439.aspx
    $code = $e->getCode();
    $error_message = $e->getMessage();
    echo $code.": ".$error_message."<br />";
    }
    
    ?>
    

    错误消息:此页面不工作 sen.azurewebsites。net当前无法处理此请求。 HTTP错误500

    1 回复  |  直到 8 年前
        1
  •  2
  •   Aaron Chen    8 年前
    1. 您的连接字符串不正确。

      • 的价值 默认端点协议 应该是 https http ,而不是blob文件的URL。

      • 对于 帐户名称 AccountKey 您可以从 Azure portal :

      enter image description here

    2. 在Windows平台上,需要将文件路径更改为:

      $content = fopen("D:\\home\\site\\wwwroot\\blobfile.txt", "r");