简体   繁体   中英

C# Upload files into a folder in azure blob storage

I know that we can upload files to azure blob storage using below:

        CloudBlockBlob cloudBlockBlob = fileContainer.GetBlockBlobReference(fileName);
        await cloudBlockBlob.UploadFromFileAsync(fileFullPath);

I already created some folders in the container. I tried a few time but the files always uploaded outside the folder.

How do we upload the files into a specific folder in the blob storage?

I guess you have to get the right reference first ( you need to include the fullpath of the file in the GetBlockBlobReference) as in :

 CloudBlockBlob cloudBlockBlob = fileContainer.GetBlockBlobReference($"yourfoldername/{fileName}");

One important thing is you DON'T need to create folder, it will automatically create it for you based on your path in the GetBlockBlobReference.

Actually there aren't real folders in Azure Blob Storage, it's just a virtual concept. In other words, Azure Blob Storage only has simple 2-level "container - blob" structure, the so-called "folders" are just prefixes of existing blob names.

For example, if there is a blob named a/b/c.jpg . The a and b are virtual folder names, you can't directly create or delete them, they exist there just because of blob a/b/c.jpg .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM