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

我正在尝试在 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 插件。


蓝山帝景
浏览 176回答 1
1回答

慕标琳琳

根据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。因此,如果不更改插件的任何代码,将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'。
打开App,查看更多内容
随时随地看视频慕课网APP