user584018
user584018

Reputation: 11364

upload files azure blob storage using container url

I am able to upload files to azure blob storage using below C# code,

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("StorageKey");

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = 
blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
  blockBlob.UploadFromStream(fileStream);
}

Here I'm supplying blob storage connection string and container name.

Now, I can see I have URL under Container Properties,

https://test.blob.core.windows.net/containerId

Question, can I write C# code that will user above URL to upload files instead of using connection string/container name?

Upvotes: 1

Views: 1167

Answers (1)

Leonardo
Leonardo

Reputation: 11401

No you can't, and the reason is simple: / is a valid char for container name. EG: you can have the container named mycontainer/folder/subFolder

Upvotes: 1

Related Questions