senny / pdfjs_viewer-rails

PDF.js viewer packaged as a Rails engine.
MIT License
114 stars 175 forks source link

pdf_url error (probably just me) #39

Closed brendangillies closed 7 years ago

brendangillies commented 7 years ago

Apologies if this is the wrong place for this - But I'm struggling with basic implementation.

In the code below, where is the pdf_url: option looking? Is there a best place in the application to store your pdf files?

<%= pdfjs_viewer pdf_url: "/sample.pdf", style: :minimal %>

I've been trying to resolve the following error for quite awhile without success:

PDF.js v1.7.225 (build: 17d135f) Message: Missing PDF "http://localhost:3000/sample.pdf".

I have a sample.pdf file in the root of my application.

senny commented 7 years ago

@brendangillies where exactly is the sample.pdf in your application structure? For this to work, it should be in public/ and Rails needs to be configured in a way that it serves assets from public/.

siegy22 commented 7 years ago

@brendangillies You should also check for permissions of the sample.pdf file. Check the application logs, maybe they'll give you some information. Did you try to access it directly through your browser?

To answer Is there a best place in the application to store your pdf files?: If you only have public accessible data, you can put them in public/<somewhere>. But if you need a permission check, you should put them in a seperate folder like <Rails.root>/uploads, and then use send_file to send it from your rails app. To speed up the file download, you can use mod_xsendfile (apache) or x-accel (nginx). See nginx tutorial and apache tutorial

EDIT: I just saw that you wrote sample.pdf file in the root of my application. Rails will only serve static files from the public/ subfolder, you should put it there.

brendangillies commented 7 years ago

Hi Yves,

Thank you very much for this information - I'm not sure why but for some reason I assumed that the pdf would not come through the asset pipeline.

The application I'm working on will display confidential pdf information, so I'll have to pursue the separate folder option you've described.

I am unable to try the proposed solution until later tonight (I live in Western Canada) - I will let you know ASAP when I am able to successfully implement.

Thanks again,

Best, Brendan

On Mon, Oct 23, 2017 at 2:44 AM, Yves Siegrist notifications@github.com wrote:

You should check for permissions of the sample.pdf file. Also check the application logs, maybe they'll give you some information.

To answer Is there a best place in the application to store your pdf files?: If you only have public accessible data, you can put them in public/. But if you need a permission check, you should put them in a seperate folder like /uploads, and then use send_file http://api.rubyonrails.org/classes/ActionController/DataStreaming.html#method-i-send_file to send it from your rails app. To speed up the file download, you can use mod_xsendfile (apache) or x-accel (nginx). See nginx tutorial https://mattbrictson.com/accelerated-rails-downloads and apache tutorial https://makandracards.com/makandra/990-speed-up-file-downloads-with-rails-apache-and-x-sendfile

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/senny/pdfjs_viewer-rails/issues/39#issuecomment-338589143, or mute the thread https://github.com/notifications/unsubscribe-auth/APpkCIFrujfWvS7SGygi9tRhLAccvyjIks5svFHTgaJpZM4QBrH5 .

-- Brendan Gillies EIT brendangillies.com linkedin.com/in/brendangillies

siegy22 commented 7 years ago

@brendangillies please check my edit.. you probably didn't get an update via email.

senny commented 7 years ago

Closing for the same reason as #40.

The question is mostly about Rails and not this gem. All that pdfjs_viewer-rails needs is a file that's accessible via a URL. For further details on how to implement something like this, please consult a Rails support forum or Stack Overflow.