2
votes

Our application enables users to upload files via a web browser. The file name gets mapped to a GUID and the blob name becomes the GUID. When the user clicks the file in our application it should download to their file system (show save as, etc) using the original file name and not the GUID blob name.

I found this post, and similar posts that describe how to set the Content-Disposition on the blob when downloading through a Shared Access Signature.

Friendly filename when public download Azure blob

However, our situation is a little different. We set a single SAS at the Container level (technically this is called a Shared Access Policy I believe -- you can have up to 5 at any given time). When downloading the blob, we simply append the SAS to the end of the uri, and use...

window.location.href = blobUri + containerSAS;

...to download the blob. This downloads the blob, but uses the GUID filename.

How can we take an existing SAS that applies to the Container and have the blob download as the original filename?

Keep in mind this is a slightly different use case from a SAS applied to an individual blob in that...

  1. The SAS is at the Container level (it seems this is the best practice vs. individual SAS's for each blob).
  2. We are downloading from javascript (vs. C# code where you can set the headers).

I have tried to set the Content-Disposition of the blob during the upload process (PUT operation), but it doesn't seem to make a difference when I download the blob. Below, you can see the Content-Disposition header being set for the PUT request (from Fiddler).

enter image description here

Thanks!

1
Is it possible for you to generate a SAS on blob using Container Access Policy or do you have to use the Container SAS token?Gaurav Mantri

1 Answers

1
votes

I have a solution. I think it's more of a workaround, but for each file to be downloaded, I make a server call and create a special SAS for the download operation. I can set Content-Disposition with that, and now the GUID named blobs are downloading with their original filenames.