intbot / ng2-pdfjs-viewer

An angular component for PDFJS and ViewerJS (Supports all versions of angular)
Apache License 2.0
231 stars 114 forks source link

Not opening pdf stored in aws S3 #9

Closed MeTushar closed 5 years ago

MeTushar commented 6 years ago

Not able to open pdf hosted in the foreign domain. Getting cors error. Is there any option to load pdf hosted in aws s3?

codehippie1 commented 6 years ago

Please post all relevant code and errors

This issue is not specific to this component. Have you tried to use jsonp or something similar? Another way to approach the problem might be to use iframes.

ani2479 commented 6 years ago

Hi,

I'm also trying to get an AWS file to display it.

Any news on this? I know I'm getting issues with CORS and trying to configure my bucket with this, but I'm still getting errors.

https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html

Thank you in advance.

javid-abd commented 6 years ago

Could you please share your code?

ani2479 commented 6 years ago

I found the solution, thanks.

I just sent from my api the PreSigned URL and it is working now

javid-abd commented 6 years ago

Then I assume the issue can be safely closed

manikumarbhasuri commented 6 years ago

I found the solution, thanks.

I just sent from my api the PreSigned URL and it is working now

Hi, I am using Pre Signed URL to display the S3 URL. First up i got "File Origin does not match" some how fixed that issue. After fixing that issue i am getting below error.

Error: Unexpected server response. Can you please guide me here.

codehippie1 commented 5 years ago

@ani2479 For the benefit of others, would you be able to share the relevant code(which shows how to use a Presigned Url) ?

javid-abd commented 5 years ago

I'm not using this package, if you have specific errors, please share your code

codehippie1 commented 5 years ago

As the OP found the answer, closing this issue

EchelonEric commented 5 years ago

I want to follow up on this as I was uploading a generated PDF to Amazon s3 and then trying to use the s3 bucket URL to ng2-pdfjs but was hitting CORS errors in Chrome. The s3 bucket was a public bucket and there are CORS policies you can configure on the bucket itself. By default there are none, and that produces this wonderful error:

the has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

To fix this, you need to set a CORS policy on your bucket: Go to AWS Console > S3 > Your Bucket > Permissions > CORS Configuration and add something like this in the CORS configuration editor:

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>*</AllowedOrigin>
   <AllowedMethod>GET</AllowedMethod>
   <AllowedHeader>*</AllowedHeader>
 </CORSRule>
</CORSConfiguration>

Click on Save and you should now be able to load the s3 bucket PDF in ng2-pdfjs.

https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html#how-do-i-enable-cors

I hope that helps someone in the future with using s3 and ng2-pdfjs.

BallisticPain commented 4 years ago

What I ended up needing to do before even running into the CORS issue(s) was to encodeURIComponent(awsS3Url) or I would just end up with an invalid URL due to how it is being passed into the iFrame. Thought I would throw that out to those that may not be getting a CORS error.