Keep getting old version, even after changing the

2019-04-16 17:26发布

问题:

background:

I'm trying to force the browser to download an image in response to a button (or link) click, instead of showing it inline. I need this to work cross browsers, so HTML5 attributes aren't enough.

The Image is stored in a blob (azure storage services).

What I tried:

  1. To set the DefaultServiceVersion to 2013-08-15 so the contentDisposition will work. (example from here Azure Storage API ContentDisposition):

    var cloudStorageAccount = new CloudStorageAccount(new StorageCredentials("accountname", "accountkey"), false);
    var serviceProperties = cloudStorageAccount.CreateCloudBlobClient().GetServiceProperties();
    serviceProperties.DefaultServiceVersion = "2013-08-15";
    cloudStorageAccount.CreateCloudBlobClient().SetServiceProperties(serviceProperties);
    
  2. To set the content disposition property (example from http://www.tuicool.com/articles/AFbmY3):

    blob.Properties.ContentDisposition = "attachment; filename=" + downloadName;
    
  3. To Call the image from a link click\window.open(image_url)\window.location = image_url. With fiddler in the background.

The problem: The image is shown by IE as an in-line image. Checking on fiddler and see that:

  1. The contentDisposition doesn't exist in the response header.

  2. The x-ms-version in the response is not the one I set as the default one. I'm Keep getting the old version 2009-09-19.

So I also tried to generate the request directly from fiddler, with the x-ms-version specified in the request header. This does work and I'm getting the response I'm expecting for, with the contentDisposition property and the right x-ms-version (the one I added to the request - 2013-08-15).

I understand that the problem is with the default service version and when i check (while debugging) the value of the DefaultServiceVersion property I do see the right value(2013-08-15), but still the response contains the old value.

I can't add x-ms-version to the header while generating the request from a link (or from window.open) and I don't really understand why the default value I added isn't working.

Thanks in advance for any help or suggestion how to solve this issue.

回答1:

I think I know what's happening. Please check out this link: http://msdn.microsoft.com/en-us/library/azure/dd894041.aspx (Go to the section titled: Requests Via Anonymous Access which reads)

If a request to the Blob service does not specify the x-ms-version header, and the default version for the service has not been set using Set Blob Service Properties, then the earliest version of the Blob service is used to process the request. However, if the container was made public with a Set Container ACL operation performed using version 2009-09-19 or newer, then the request is processed using version 2009-09-19.

Most likely you created the container or changed it's ACL before changing the service version and thus if no service version is provided, it is using the older version.

You can try two things:

  1. Create a new blob container with ACL as public and try downloading a blob from there. Since the container is created with new service version, you should not encounter this error.
  2. Change the container ACL to Private and then change it back to Public. Since the operation is now performed with the latest version of library (I'm assuming), you should not encounter this error when downloading blob.