Search code examples
bashazureterminalazure-cli

How do I upload a file to Azurite from terminal?


I'm using Azurite and wish to create a container/upload a blob etc from the bash terminal!

I've tried using the Azure CLI like this::

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

This fails with Authentication failure. By the way the correct account key and name are used in that example.

I believe it's not possible to talk to Azurite using the Azure CLI.

All I want to do is create a container and upload a file to it from the terminal.

Does anybody know if this is possible? Or will I have to use a Java client (for example) to do the job?


Solution

  • According to my test, when we account key and account name with Azure CLI to create blob container, cli will use https protocol to connect Azurite. But, in default, Azurite just support http protocol. For more details, please refer to here
    enter image description here

    So I suggest you use connection string to connect Azurite with Azure CLI, the connection string will tell Azure CLI uses http protocol.

    For example

    1. Create contanier
    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. Upload file
    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