How do I upload a file to Azurite from terminal?
Asked Answered
S

2

8

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?

Suddenly answered 18/8, 2020 at 18:34 Comment(0)
B
12

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

Bivins answered 20/8, 2020 at 0:47 Comment(3)
This works! I tried to do the same thing using Https, and it fails with this error: Max retries exceeded with url: /devstoreaccount1/identity?restype=container (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),)). HTTPSConnectionPool(host='127.0.0.1', port=10000): Any pointers?Denice
@Denice If you want to use HTTPS, please refer to github.com/Azure/Azurite#https-setupBivins
I have followed all the steps and I can view my storage account in AzureStorageExplorer. But when I try to add a blobcontainer using the commands above, it throws the error.Denice
P
-1

If you want to use a non terminal way of doing it, use the Azure Storage Explorer after Azurite is running:

enter image description here

Percy answered 1/8 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.