Is it possible to the content disposition of an ex

2019-07-20 22:37发布

问题:

Based on stimms answer here: Azure Storage API ContentDisposition

and the information found here: Friendly filename when public download Azure blob

I have been able to set the content disposition when uploading new files. But I also would like to be to able to set the content disposition of existing files.

blob.Properties.ContentDisposition = string.Format("attachment;filename=\"{0}\"", friendlyName);

works fine when set before uploading a file, but has no effect if I try it on an existing blob.

Is is just plain impossible to change the content disposition of an existing blob or am I doing something wrong?

回答1:

Yes. You just have to call SetProperties() method on the blob after you set ContentDisposition. So your code should be:

            blob.FetchAttributes();//Fetch properties first so that you don't overwrite existing properties when you call SetProperties
            blob.Properties.ContentDisposition = string.Format("attachment;filename=\"{0}\"", friendlyName);
            blob.SetProperties();