azure-blob-storageazure-logic-appsblobstorage

SAS URI of a csv or json blob generaed in Logic app displayes the content in browser instead of downloading the file


I have created a blob file in Azure storage using an Azure Logic App.

I add CSV content and name the file data.csv, or I add JSON content and name the file data.json, and then I generated the SAS URI of the file.

If we paste the URL in browser, the browser displays the content of the file instead of downloading it.

What steps will have to be taken so that the URL is generated such that the file can be downloaded instead of displaying content in browser. As the content of the file can be in 100s of MB.

In the Logic app, Create blob (V2) connector, when I specified Content-Type as test/csv, the generated SAS URI was a downloadable file.

But when I add a JSON content and set Content-Type as application/json, the generated SAS URI displays the JSON content in browser.

Why isn't the behavior same for all URL?


Solution

  • 3 ways to solve this problem:

    1. Change Content-Type of the blob to application/octet-stream: You can try by changing the content type of the blob to application/octet-stream. In some browsers, it will download the csv file. Please note that you will lose the ability to view the contents inline in those browsers.

    2. Set Content-Disposition response header of the blob: You can se the Content-Disposition response header of the blob to attachment; filename="data.csv". Then your blob will always be downloaded. Please note that here you will always lose the ability to view the contents inline for this file and it will always be downloaded.

    3. Override Content-Disposition response header of the blob in SAS URL: This is the most preferred way. When creating SAS URL of the blob, you can set the Content-Disposition response header to Content-Disposition response header of the blob to attachment; filename="data.csv". Now when you access the blob through this SAS URL, it will always be downloaded. I wrote a blog post about it long time ago that you can read here: https://gauravmantri.com/2013/11/28/new-changes-to-windows-azure-storage-a-perfect-thanksgiving-gift/.