skip to Main Content

Hi I am using Azure blob storage and upload. Using ASP.NET MVC 4.8 to upload/download files.
I want to know how I can download files without specifying the path to download. That means I want to download the files into browser download folder.

I am able to download the files using :

 BlobDownloadResult downloadResult = blobClient.DownloadContent();
 return downloadResult;

and

blobContainerClient.DownloadTo(path); //but I don't want to download to 
                                       //local folder

But trying to figure out how I can download in browser.
I also need to consider I may have situation there files are big e.g 4 gig.

2

Answers


  1. To enable downloading files from Azure Blob Storage directly to the browser’s download folder without specifying a path, you can use the Content-Disposition header with the value attachment in the HTTP response. This header instructs the browser to treat the response as a downloadable file and prompts the user to save it.

    // Set the response content type based on the file's MIME type
    Response.ContentType = blob.Properties.ContentType;
    
    /
    
    Login or Signup to reply.
  2. In the above example, you need to replace "your_connection_string" with your actual Azure Blob Storage connection string and "your_container_name" with the name of your container. By setting the Content-Disposition header to "attachment", the browser should prompt the user to save the file to their download folder. Note that downloading large files (e.g., 4 GB) directly from the Azure Blob Storage might not be optimal due to potential timeouts and performance issues. In such cases, you may want to consider implementing a streaming approach or providing the user with a temporary download link that expires after a certain period.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search