我想使用pdf.js與範圍請求(漸進式加載的PDF文檔),但是當我試圖加載從Amazon S3的網址的PDF文件出現在控制檯此錯誤:拒絕從pdf.js與亞馬遜網址獲取不安全標題「接受範圍」錯誤
-Refused得到不安全的報頭「接受範圍」
和PDF不經由206部分內容(範圍請求),但200和負載然後在查看器中查看。
這是PDF格式的URL的一個例子:
任何幫助
我想使用pdf.js與範圍請求(漸進式加載的PDF文檔),但是當我試圖加載從Amazon S3的網址的PDF文件出現在控制檯此錯誤:拒絕從pdf.js與亞馬遜網址獲取不安全標題「接受範圍」錯誤
-Refused得到不安全的報頭「接受範圍」
和PDF不經由206部分內容(範圍請求),但200和負載然後在查看器中查看。
這是PDF格式的URL的一個例子:
任何幫助
您需要設置
Access-Control-Allow-Headers : Accept-Ranges
亞馬遜設定CORS政策這樣似乎幫助。
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<!-- this part is critical -->
<AllowedHeader>*</AllowedHeader>
<ExposeHeader>Accept-Ranges</ExposeHeader>
<ExposeHeader>Content-Encoding</ExposeHeader>
<ExposeHeader>Content-Length </ExposeHeader>
<ExposeHeader>Content-Range</ExposeHeader>
</CORSRule>
</CORSConfiguration>
但是,我把資源放在CDN後,這是行不通的。無論如何,即使在CDN上有200個,然後在S3上有206個部分下載,它似乎也快很多。
內容長度是不必要的,它會自動暴露 – 2015-02-15 17:17:35
我試過這種配置和許多類似的配置,沒有在Webkit運氣。 Safari和Chrome仍然希望拋出不安全的「Accept-Ranges」錯誤。 – BradGreens 2015-04-30 22:04:37
最後回答,但與Azure斑點(我知道你問了AWS,但這使我瘋狂試圖找出答案),你必須設置Accept-Ranges作爲允許標題,只需將其設置爲*
不起作用。
我用下面的C#代碼做到這一點:
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);
謝謝,這節省了我很多時間! – guyfromfargo 2017-01-23 18:15:44
我也得到了同樣的問題。我沒有直接傳遞url,而是使用url =「url」和withCredentials = true傳遞了對象。通過直接鏈接
當CHK以下爲如何形成 PDF.JS: Render PDF using an ArrayBuffer or Blob instead of URL
這似乎不會是一個普通的HTTP報頭字段對象
的Cookie沒有得到通過。 http://en.wikipedia.org/wiki/List_of_HTTP_header_fields – 2014-10-29 11:55:41
「根據https://www.html5rocks.com/en/tutorials/cors/#toc-」所有CORS相關標題前綴「訪問控制 - 」「處理一個簡單的請求 – Stevko 2017-05-18 20:32:31