【发布时间】: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