Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 209
Coolguy Avatar asked Dec 23 '22 05:12

Coolguy


1 Answers

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.

like image 54
Dan Hunex Avatar answered Jan 06 '23 17:01

Dan Hunex