azureuploadwebapifileshareiformfile

Azure File Share Implementation in .Net Core Web API


Can any one suggest how to Upload a file to Azure File Share in.Net Core Web API? I'm using IFormFile to Upload File.

Note: I'm trying to upload Excel(*.xlsx) File.


Solution

  • Did you had a look at the documentation already?

    https://learn.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files https://learn.microsoft.com/en-us/dotnet/api/azure.storage.files.shares.sharefileclient.uploadasync?view=azure-dotnet

    It should look similar to this (Note: this code is not functionally, just made it up by memory)

        var file = Request.Form.Files[0];
        if (file.Length > 0)
        {
            Stream fileStream = file.OpenReadStream();
            shareFileClient.UploadAsync(fileStream); 
            
        }