0 votes
1 view
in AWS by (16.7k 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 (39.6k 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !

Categories

...