为了账号安全,请及时绑定邮箱和手机立即绑定

尝试在 Laravel 中使用 Azure 存储模拟器

尝试在 Laravel 中使用 Azure 存储模拟器

PHP
蓝山帝景 2022-07-16 10:54:15
我正在尝试在 Laravel 5.8 中实现 Azure 存储模拟器它适用于 Azure 开发和生产,但不适用于本地 Windows。邮递员返回"message": "Fail:\nCode: 403\nValue: Server failed to authenticate the request.确保 Authorization header 的值包括签名在内的格式正确。\ndetails (if any): .",    "异常": "MicrosoftAzure\\Storage\\Common\\Exceptions\\ServiceException",    "file": "C:\\Code\\web-portal-laravel\\vendor\\microsoft\\azure-storage-common\\src\\Common\\Internal\\ServiceRestProxy.php",像公共和私人文件夹一样,我们正在尝试将其实现为存储磁盘。我们认为只使用相同类型的条目 - 而是使用 .env 文件中的共享密钥凭据会起作用:    AZURE_STORAGE_URL_EMU = "http://127.0.0.1:10000/devstoreaccount1/local"    AZURE_STORAGE_KEY_EMU =        "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVERCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="    AZURE_STORAGE_ACCOUNT_EMU = "devstoreaccount1"    AZURE_STORAGE_CONTAINER_EMU = "本地"存储资源管理器已安装并可以看到 Blob、队列和表。模拟器的状态报告:    Windows Azure Storage Emulator 5.10.0.0 命令行工具    正在运行:真    BlobEndpoint:http://127.0.0.1:10000/    队列端点:http://127.0.0.1:10001/    表端点:http://127.0.0.1:10002/我不知道什么样的 Authorization 标头可以使它起作用。我们正在使用 matthewbdaly/laravel-azure-storage 插件。
查看完整描述

1 回答

?
慕标琳琳

TA贡献1830条经验 获得超9个赞

根据Connect to the emulator account using the well-known account name and key官方文档的部分Use the Azure storage emulator for development and testing,Azure Storage Emulator 的连接字符串应该如下所示。


DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;

AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;

BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;

TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;

QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;

src/AzureStorageServiceProvider.php看了下plugin的源码matthewbdaly/laravel-azure-storage,发现下图的代码只支持云上Azure Storage的连接字符串,不支持Emulator。

//img1.sycdn.imooc.com//62d229370001550509540851.jpg

因此,如果不更改插件的任何代码,将config/filesystems.php文件配置为插件 repo 的内容的解决方法README如下。


'azure' => [

        'driver'    => 'azure',

        'name'      => 'devstoreaccount1',

        'key'       => 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;',

        'container' => env('AZURE_STORAGE_CONTAINER'),

        'url'       => env('AZURE_STORAGE_URL'),

        'prefix'    => null,

],

然后,模拟器连接字符串可以正确地由key上面的值与字符串模板代码补充'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s'。


查看完整回答
反对 回复 2022-07-16
  • 1 回答
  • 0 关注
  • 175 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号