I'm having a hard time figuring out how to add a file to this emulator in order to test azure blob different operations locally.
Asked
Active
Viewed 5,494 times
3
-
Hasn't this problem been solved yet? You can tell me, maybe I can help you. – Frank Borzage Aug 06 '20 at 01:20
-
@FrankGong I was trying to use azcopy but It didn't work to copy a local file to azurite using copy command – Ziad Adeela Aug 06 '20 at 06:18
-
You can look at the blog at the end of the answer I gave. `Azurite` has a default [connection string](https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite#https-connection-strings), you can configure it in the `local.settings.json` file, and then the other steps are the same as creating a function to upload files to blob storage, you can use the SDK to write code normally, and upload files to azurite. – Frank Borzage Aug 06 '20 at 07:18
-
@FrankGong, Maybe you can help, i have docker container with app and i want to have azurite storage in separate docker container which can upload, give and delete data on request from the first container with app. All this using python. Can you share an idea or link on some manuals how it done? – Vadim Jan 18 '22 at 18:05
2 Answers
1
After you install azurite, you need to start it manually.
There are two ways to connect to Azurite:
The next step I think is the same as using azure storage in the cloud, only need to use sdk for blob operation:
var blobHost = Environment.GetEnvironmentVariable("AZURE_STORAGE_BLOB_HOST"); // 126.0.0.1:10000
var account = Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT"); // devstoreaccount1
var container = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONTAINER");
var emulator = account == "devstoreaccount1";
var blobBaseUri = $"https://{(emulator ? $"{blobHost}/{account}" : $"{account}.{blobHost}")}/";
var blobContainerUri = $"{blobBaseUri}{container}";
// Generate random string for blob content and file name
var content = Guid.NewGuid().ToString("n").Substring(0, 8);
var file = $"{content}.txt";
// With container uri and DefaultAzureCredential
// Since we are using the Azure Identity preview version, DefaultAzureCredential will use your Azure CLI token.
var client = new BlobContainerClient(new Uri(blobContainerUri), new DefaultAzureCredential());
// Create container
await client.CreateIfNotExistsAsync();
// Get content stream
using var stream = new MemoryStream(Encoding.ASCII.GetBytes(content));
// Upload blob
await client.UploadBlobAsync(file, stream);
You can refer to this official document, it has a more detailed tutorial. Or you can refer to this blog.

Frank Borzage
- 6,292
- 1
- 6
- 19
0
Azurite needs to be up and run in given ports . then you can access it.
main point is use the connection string as follows
**"AzureStorage": {
"ConnectionString": "UseDevelopmentStorage=true;",**
Then follow the below github code. https://github.com/chatchathu199162/BlobUpdate/blob/master/BlobUpdate/BlobUpdate.csproj

Chathu.Thanthrige
- 103
- 7