Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I'm trying to use pdf.js with range requests (progressive loading of the pdf document), but when I'm trying to load the pdf from amazon s3 urls this error appears in the console :

-Refused to get unsafe header "Accept-Ranges"

and the pdf doesn't load via 206 partial content (range requests) but 200 and then viewed in the viewer.

1 Answer

0 votes
by (44.4k points)

Set your Amazon CORS policy like this:

<?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>

This might help.

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
asked Aug 14, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
asked Jan 2, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...