如何从终端上载文件到Azurite?

问题描述

我正在使用Azurite,并希望从bash终端创建一个容器/上传blob等!

我已经尝试过使用Azure CLI:

az storage container create --account-name devstoreaccount1 --account-key Eby8vdM02xNOcqFlqUwjpllmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw== --name mycontainer

但是,它当然不起作用,并且抱怨认证失败!顺便说一下,在该示例中使用了正确的帐户密钥和名称

我相信无法使用Azure CLI与Azurite对话。

要做的就是创建一个容器,然后从终端上载文件

有人知道这是否可能吗?还是我必须使用Java客户端(例如)来完成这项工作?

谢谢

解决方法

根据我的测试,当我们使用Azure CLI对密钥和帐户名称进行帐户创建blob容器时,cli将使用https协议连接Azurite。但是,默认情况下,Azurite仅支持http协议。有关更多详细信息,请参阅here
enter image description here

因此,我建议您使用连接字符串将Azurite与Azure CLI连接,该连接字符串将告诉Azure CLI使用http协议。

例如

  1. 创建容器
az storage container create -n test --connection-string "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;"

enter image description here

  1. 上传文件
az storage blob upload -f D:\test.csv -c test -n test.csv --connection-string "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;"

enter image description here