Azure blob upload rename if blob name exist

Viewed 2055

In Azure blob upload, a file is overwritten if you upload a new file with the same file name (in the same container).

I would like to rename the new file before saving it, to avoid overwriting any files - Is this possible?

Scenario:

  1. Upload file "Image.jpg" to container "mycontainer"
  2. Upload file "Image.jpg" to container "mycontainer" (with different content)
  3. Rename second "Image.png" to "Image_{guid}.jpg" before saving it to "mycontainer".
3 Answers

Needing to rename may be indicative of an anti-pattern. If your ultimate goal is to change the name of the file when downloaded, you can do so and keep the blob name abstract and unique.

You can set the http download filename by assigning ContentDisposition property with

attachment;filename="yourfile.txt"

This will ensure that the header is set when the blob is accessed either as public or a SAS url.

Related