【问题标题】:Access to Blob Storage from PHP Running on Azure Web App从运行在 Azure Web App 上的 PHP 访问 Blob 存储
【发布时间】:2017-02-24 10:04:03
【问题描述】:

我试图让在 Azure Web 应用程序上运行的 PHP wiki 访问我的 Azure Blob 存储以引用其内容,但在引用 blob 容器时似乎有一些问题。

根据一些参考资料,我已将 composer 和 microsoft/windowsazure 插件安装到我的应用程序中。供应商文件夹的位置是 D:\site\wwwroot\wiki\bar\vendor。

我也用下面的代码创建了index2.php(目前使用的是index.php)。

<?php

ini_set("display_errors", On);
error_reporting(E_ALL);

require_once 'vendor\autoload.php';

use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;

// Create blob REST proxy.
$connectionString = "DefaultEndpointsProtocol=https;AccountName=<account name>;AccountKey=<key>;";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);


try {
    // List blobs.
    $blob_list = $blobRestProxy->listBlobs("wiki");
    $blobs = $blob_list->getBlobs();

    foreach($blobs as $blob)
    {
        echo $blob->getName().": ".$blob->getUrl()."<br />";
    }
}
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 />";
}

但是,我在运行时遇到了这个错误。

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'The path of a URI with an authority must start with a slash "/" or be empty' in D:\home\site\wwwroot\wiki\bar\vendor\guzzlehttp\psr7\src\Uri.php:693
Stack trace:
    #0 D:\home\site\wwwroot\wiki\bar\vendor\guzzlehttp\psr7\src\Uri.php(502): GuzzleHttp\Psr7\Uri->validateState()
    #1 D:\home\site\wwwroot\wiki\bar\vendor\microsoft\azure-storage\src\Common\Internal\ServiceRestProxy.php(124): GuzzleHttp\Psr7\Uri->withPath('wiki')
    #2 D:\home\site\wwwroot\wiki\bar\vendor\microsoft\azure-storage\src\Blob\BlobRestProxy.php(1181): MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy->send('GET', Array, Array, Array, 'wiki', 200)
    #3 D:\home\site\wwwroot\wiki\bar\index2.php(18): MicrosoftAzure\Storage\Blob\BlobRestProxy->listBlobs('wiki')
    #4 {main} thrown in D:\home\site\wwwroot\wiki\bar\vendor\guzzlehttp\psr7\src\Uri.php on line 693

难道不能用这种php代码从这个位置访问存储吗?

【问题讨论】:

    标签: php azure azure-blob-storage


    【解决方案1】:

    我找到了解决办法。

    正如错误消息所说,有必要将“/”放在“wiki”之前,这是容器名称。 azure.microsoft.com 上的说明没有放置标志,因此我仍然找不到解决方案的原因...

    【讨论】:

      猜你喜欢
      • 2018-09-26
      • 2020-06-03
      • 2021-12-18
      • 2017-12-20
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 2019-10-14
      • 2016-05-16
      相关资源
      最近更新 更多