Alcumus / react-doc-viewer

Apache License 2.0
208 stars 101 forks source link

CORS Policy Issue #59

Closed wkungu closed 3 years ago

wkungu commented 3 years ago

Hi,

I'm getting Access to fetch at 'https://remote_server/sample.pdf' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. while loading a remote file.

How do I resolve this on react-doc-viewer?

Thanks

mattmogford-alcumus commented 3 years ago

@wkungu The issue here is that the server you are trying to access the pdf from, has a CORS policy that doesn't allow your localhost connection to download it's files. If you are just testing sample files, it would be easier to download the pdf and load it locally. Or have you're own server hosting the files, with your own CORS policy. Google Firebase has a level of free storage/hosting you could use I believe. Here is a CORS free sample pdf https://file-examples-com.github.io/uploads/2017/10/file-sample_150kB.pdf

drewjulo commented 3 years ago

I host my files using aws and set my cors policy as below

[ { "AllowedHeaders": [ "" ], "AllowedMethods": [ "GET", "HEAD" ], "AllowedOrigins": [ "" ], "ExposeHeaders": [], "MaxAgeSeconds": 3000 } ]

and i'm still facing this issue

mattmogford-alcumus commented 3 years ago

I host my files using aws and set my cors policy as below

[ { "AllowedHeaders": [ "" ], "AllowedMethods": [ "GET", "HEAD" ], "AllowedOrigins": [ "" ], "ExposeHeaders": [], "MaxAgeSeconds": 3000 } ]

and i'm still facing this issue

Hi, Sorry this would be an aws / server issue

wkungu commented 3 years ago

This worked for me on AWS.


[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "HEAD"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": []
    }
]