当请求文件时,如何让Azure在响应中返回“Accept

编程入门 行业动态 更新时间:2024-10-26 23:24:59
当请求文件时,如何让Azure在响应中返回“Accept-Ranges”和“Content-Encoding”标头?(How do I get Azure to return the 'Accept-Ranges' and 'Content-Encoding' headers in the response when a file is requested?)

我正在使用Azure blob存储,当我对文件执行GET请求时,我希望响应包含“Accept-Ranges”和“Content-Encoding”的标头。

我已经针对我的blob服务器运行了以下代码,首先允许这些:

var url = new Uri(String.Format("https://yourblob.blob.core.windows.net")); var credentials = new StorageCredentials("accountname", "key"); var client = new CloudBlobClient(url, credentials); var corsRule = new CorsRule(); corsRule.ExposedHeaders.Add("Accept-Ranges"); corsRule.ExposedHeaders.Add("Content-Encoding"); corsRule.ExposedHeaders.Add("Content-Length"); corsRule.ExposedHeaders.Add("Content-Type"); corsRule.AllowedHeaders.Add("Accept-Ranges"); corsRule.AllowedHeaders.Add("Content-Encoding"); corsRule.AllowedHeaders.Add("Content-Length"); corsRule.AllowedHeaders.Add("Content-Type"); var serviceProperties = CloudBlobClient.GetServiceProperties(); serviceProperties.Cors.CorsRules.Clear(); serviceProperties.Cors.CorsRules.Add(corsRule); client.SetServiceProperties(serviceProperties);

这似乎有效,因为之前当我在返回的对象上运行以下Javascript时,我收到一条错误,说Refused to get unsafe header "Accept-Ranges" ,我不再收到此错误:

var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId); if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') { return; }

但标题也不存在。 我发现这篇博文建议将我的azure blob服务器的DefaultServiceVersion更改为“2012-02-12”。 我已经这样做了,但仍然没有看到所需的标题。

我需要这些用于我正在使用的库(pdf.js),如果存在这些库,则允许以块的形式加载pdf文件。 也许在上传之前我需要对文件做些什么?

任何帮助将不胜感激,谢谢。

I am using Azure blob storage, and when I do a GET request for a file I want the response to include headers for 'Accept-Ranges' and 'Content-Encoding'.

I have ran the following code against my blob server to first allow these:

var url = new Uri(String.Format("https://yourblob.blob.core.windows.net")); var credentials = new StorageCredentials("accountname", "key"); var client = new CloudBlobClient(url, credentials); var corsRule = new CorsRule(); corsRule.ExposedHeaders.Add("Accept-Ranges"); corsRule.ExposedHeaders.Add("Content-Encoding"); corsRule.ExposedHeaders.Add("Content-Length"); corsRule.ExposedHeaders.Add("Content-Type"); corsRule.AllowedHeaders.Add("Accept-Ranges"); corsRule.AllowedHeaders.Add("Content-Encoding"); corsRule.AllowedHeaders.Add("Content-Length"); corsRule.AllowedHeaders.Add("Content-Type"); var serviceProperties = CloudBlobClient.GetServiceProperties(); serviceProperties.Cors.CorsRules.Clear(); serviceProperties.Cors.CorsRules.Add(corsRule); client.SetServiceProperties(serviceProperties);

This seems to have worked because before when I ran the following Javascript on the object returned I was getting an error saying Refused to get unsafe header "Accept-Ranges", I no longer get this error:

var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId); if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') { return; }

But the header isn't present either. I found this blog post which suggested changing the DefaultServiceVersion of my azure blob server to "2012-02-12". I have done this and am still not seeing the needed headers.

I need these for a library I am using (pdf.js) which allows, if these are present, to load a pdf file in chunks. Maybe there is something I need to do to the file before it is uploaded?

Any help would be appreciated, thanks.

最满意答案

在Windows中, Azure Management Studio使通过GUI管理CORS问题变得非常容易

In Windows, Azure Management Studio made it very easy to manage CORS Issues through GUI

更多推荐

本文发布于:2023-08-02 21:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1381463.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Azure   Accept

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!