我正在使用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
更多推荐
发布评论