John
John

Reputation: 6612

Images not rendered with secure connection to Amazon S3

I am creating a PDF which contains images which are stored on Amazon S3. My Rails application uses https, so also the URL to the S3 image is https, which is configured in production.rb:

config.paperclip_defaults = {
  :storage => :s3,
  :s3_protocol => :https
}

The issue is that the S3 bucket has a security bucket policy that it only shows the image when it is coming from my web domain. This works well when showing the image in the view, because the referer is then my web domain which is whitelisted.

The issue when creating the PDF is that wicked_pdf tries to retrieve the image, but S3 can't see it is coming from my web domain and returns a 403 Forbidden. So what can I do to solve this?

Upvotes: 4

Views: 394

Answers (2)

mrc
mrc

Reputation: 101

Is your CORS configured in AWS? https://aws.amazon.com/blogs/aws/amazon-s3-cross-origin-resource-sharing/

Upvotes: 1

Paul A Jungwirth
Paul A Jungwirth

Reputation: 24541

Since you've tagged your question with wicked-pdf I assume that's what you're using. It looks like this is a known problem with some versions of that gem. The linked question gives several options to solve it.

Upvotes: 1

Related Questions