I'm using Azurite to run tests locally about some functionality that uploads file to an Azure Blob Storage. I'm running it by using docker compose, and I would like to run it in a non-default port for the tests. The configuration I came up with is the following:
storage:
image: mcr.microsoft.com/azure-storage/azurite
environment:
- AZURITE_ACCOUNTS=account:QUJDRA==
ports:
- "10020:10000"
I'm using the following configuration to register the BlobServiceClient
service in Asp.Net Core:
services.AddAzureClients(builder =>
{
builder.AddBlobServiceClient(
new Uri("http://localhost:10020/account"),
new StorageSharedKeyCredential("account", "QUJDRA=="));
});
And the code that uploads files is as follows:
public async Task<string> UploadFile(BlobServiceClient blobServiceClient, Stream file)
{
var blobContainerClient = blobServiceClient.GetBlobContainerClient("container");
await blobContainerClient.CreateIfNotExistsAsync(PublicAccessType.BlobContainer);
var blobClient = blobContainerClient.GetBlobClient("blob");
await blobClient.UploadAsync(file);
return blobClient.Uri.ToString();
}
If I run this configuration in the default port (10000), it all works as expected, and I get the following logs from the Azurite container:
storage-1 | 172.21.0.1 - - [20/Jan/2023:11:02:35 +0000] "PUT /account/container?restype=container HTTP/1.1" 409 -
storage-1 | 172.21.0.1 - - [20/Jan/2023:11:02:37 +0000] "PUT /account/container/blob?comp=block&blockid=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA HTTP/1.1" 201 -
storage-1 | 172.21.0.1 - - [20/Jan/2023:11:02:37 +0000] "PUT /account/container/blob?comp=blocklist HTTP/1.1" 201 -
However, if I try to run it in the non-default port (10020), the line in which the file is uploaded await blobClient.UploadAsync(file)
produces the following exception:
Azure.RequestFailedException : Service request failed.
Status: 400 (Bad Request)
storage-1 | 172.25.0.1 - - [20/Jan/2023:11:18:43 +0000] "PUT /account/container?restype=container HTTP/1.1" 201 -
storage-1 | 172.25.0.1 - - [20/Jan/2023:11:18:44 +0000] "PUT /account/blob?comp=block&blockid=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA HTTP/1.1" 400 -
If you look closely to the second line of the logs, which corresponds to the upload of the file, in this case the url is missing the /container
part after the name of the account. I guess that's the reason for the 400
error.
Why is it that a change in the port is changing the url in this way? Is there any configuration that I'm missing?