Prawn image on amazon image not found
Asked Answered
S

2

15

I am using Prawn 0.12.0 in a Rails 3.2.12 app.

If I have an image on my local server it can show in a standard rails view, and I can also have it shown in a Prawn PDF using the following code

@logo = company.logo_url(:large).to_s    
image @logo, :fit => [83.mm, 26.mm]

So far, so good. If I change the location of the image to be on Amazon S3 I get the following

I am able to show in a standard Rails view no problem If I try to display the image in a Prawn pdf I get the following error

Argument error (https://mydomain.s3.amazonaws.com/uploads/company/logo/20/large_2275_logo.png not found):

And if I then copy and paste that url into a browser, the image shows fine.

So to recap...

  1. I am able to use the Prawn image command for a local image, indicating I am using the Prawn syntax correctly
  2. I can access an image on Amazon S3 using a direct browser and a Rails view, indicating that the URL is correct
  3. BUT, I can not access the image on Amazon S3 from Prawn

Has anyone seen anything similar, or have any suggestions?

Michael

Scorpaenoid answered 5/9, 2013 at 6:26 Comment(0)
J
29

I had the same problem, I've solved with

require 'open-uri'

image open("hxxp://www.thesite.com/theimage.png")

Jongjongleur answered 5/9, 2013 at 10:11 Comment(3)
Superb, thanks. Can't believe this isn't showing up more oftenScorpaenoid
Really helpful, I was also surprised this isn't a more common questionDermatoglyphics
require 'open-uri' pdf = Prawn::Document.new pdf.image open("hxxp://www.thesite.com/theimage.png")Atonsah
M
8

With the recent releases of Prawn, you can achieve loading remote images without requiring open-uri;

image open("http://example.com/remote_image.pdf"), at: [300, 100], width: 100, height: 100
Mccabe answered 21/10, 2014 at 19:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.