gpt4 book ai didi

c# - 即使更改了 azure blob 上的默认服务版本(为了设置内容处置 header ),也要继续获取旧版本

转载 作者:行者123 更新时间:2023-12-02 08:08:54 31 4
gpt4 key购买 nike

背景:

我试图强制浏览器下载图像以响应按钮(或链接)单击,而不是内联显示它。我需要它能够跨浏览器工作,因此 HTML5 属性还不够。

图像存储在 blob(Azure 存储服务)中。

我尝试过的:

  1. 将 DefaultServiceVersion 设置为 2013-08-15,以便 contentDisposition 正常工作。 (示例来自此处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. 设置内容处置属性(示例来自 http://www.tuicool.com/articles/AFbmY3):

    blob.Properties.ContentDisposition = "attachment; filename=" + downloadName;
  3. 要从链接调用图像,请单击\window.open(image_url)\window.location = image_url。后台有 fiddle 手。

问题:该图像由 IE 显示为内嵌图像。检查 fiddler 并看到:

  1. 响应 header 中不存在 contentDisposition。

  2. 响应中的 x-ms-version 不是我设置的默认版本。我继续获取旧版本 2009-09-19。

所以我也尝试直接从fiddler生成请求,并在请求header中指定x-ms-version 。这确实有效,我得到了我所期望的响应,其中包含 contentDisposition 属性和正确的 x-ms-version(我添加到请求中的版本 - 2013-08-15)。

我知道问题出在默认服务版本上,当我检查(调试时)DefaultServiceVersion 属性的值时,我确实看到了正确的值(2013-08-15),但响应仍然包含旧值.

在从链接(或从 window.open)生成请求时,我无法将 x-ms-version 添加到 header ,并且我不太明白为什么我添加的默认值不起作用。

预先感谢您提供有关如何解决此问题的任何帮助或建议。

最佳答案

我想我知道发生了什么。请查看此链接:http://msdn.microsoft.com/en-us/library/azure/dd894041.aspx (转到标题为:通过匿名访问请求的部分,内容如下)

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.

很可能您在更改服务版本之前创建了容器或更改了其 ACL,因此如果未提供服务版本,则它将使用旧版本。

您可以尝试两件事:

  1. 创建一个新的 Blob 容器,并将 ACL 设置为公共(public),然后尝试从那里下载 Blob。由于容器是使用新的服务版本创建的,因此您不应遇到此错误。
  2. 将容器 ACL 更改为 Private,然后将其更改回 Public。由于现在使用最新版本的库执行该操作(我假设),因此在下载 blob 时不应遇到此错误。

关于c# - 即使更改了 azure blob 上的默认服务版本(为了设置内容处置 header ),也要继续获取旧版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25472152/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com