Web Api Upload File|Upload File To Azure Storage Account

Опубликовано: 29 Сентябрь 2024
на канале: AzureTeach•Net
8,666
78

Web Api Upload File|Upload File To Azure Storage Account
How to upload file to azure storage account from Web API?
This demo has solution for uploading files to azure storage account using web api. To .Net 6 Web Api upload file azure storage account, we need to use IFormFile. If you use IFormFile, the swagger will show you option to choose files to upload files to Web Api.

IFormFile has option to extract stream from the file. We have to use Azure.Storage.Blobs nuget package to connect to the storage account. We can get the connection string of the storage account by navigating to the Storage account and from Access Keys, show connections strings option.

We can create blob container client and use connection string to connect to the azure storage account. Once you get the file objects in list of IFormFiles from Web Api upload file, iterate over the IFormFiles, then we have to create a stream object. We can use IFormFile's CopyTo method to copy the file stream object to the stream and can pass the stream to the blobContainerClient object's uploadBlobAsync method. This will upload the file to Azure storage account using Web Api.
Once you run the application, it will open the swagger UI as we are using .Net6 Web API upload file. There we can select the files to upload and test the application - Web API upload file to azure storage account.

Chapters
00:00 Introduction
01:27 Developing Web API Upload File to Storage Account
03:48 Testing Web API Upload file to azure storage account

#WebAPiUploadFile#
#WebApiStorageAccount#
#WebApiAzureStorageAccount#