在 Azure Web App 上从 PHP 运行 访问 Blob 存储
Access to Blob Storage from PHP Running on Azure Web App
我试图让我的 PHP wiki(它在 Azure Web App 上 运行)访问我的 Azure Blob 存储以引用其内容,但它似乎在引用blob 容器。
根据一些参考资料,我已经在我的应用程序中安装了作曲家和 microsoft/windowsazure 插件。 vendor文件夹的位置是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 代码从该位置访问存储?
我找到了解决方案。
正如错误信息所说,需要在"wiki"前加上“/”,这是容器名称。 azure.microsoft.com 上的说明没有标明,所以我仍然找不到它是解决方案的原因...
我试图让我的 PHP wiki(它在 Azure Web App 上 运行)访问我的 Azure Blob 存储以引用其内容,但它似乎在引用blob 容器。
根据一些参考资料,我已经在我的应用程序中安装了作曲家和 microsoft/windowsazure 插件。 vendor文件夹的位置是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 代码从该位置访问存储?
我找到了解决方案。
正如错误信息所说,需要在"wiki"前加上“/”,这是容器名称。 azure.microsoft.com 上的说明没有标明,所以我仍然找不到它是解决方案的原因...