问题
I'm trying to display a preview of the uploaded pdf in my application but all I get so far is a broken image.
I have installed the poppler gem as suggested in the active storage presentation for preview.
Then i tried different ways but all are returning a broken image.
<%= link_to bank.rib, rails_blob_path(bank.rib, disposition: "preview") %>
or
<%= image_tag bank.rib %>
or
where 'rib
' being the attached file (has_one
) of the model BankAccount (here bank = BankAccount.find(id)
)
bank.rib.previewable?
returns true
.
回答1:
Installing poppler, is just one of the steps you might need, here are some other things you should check:
- Rails might be requiring some additional gems installed:
You must have ImageMagick or GraphicsMagick installed
Add this to your Gemfile:
gem 'image_processing', '~> 1.2'
and install imagemagick:
brew install imagemagick
- Another possible issue is that your application cannot reach the /rails/active_storage path, so verify the path is mounted or you do not have a catch_all route that overwrites that path, in case you do, you can exclude rails path with the following:
get "*unmatched_route", constraints: -> (req) { !(req.fullpath =~ /^\/rails\/(active_storage|conductor|action_mailbox)\/.*/) }
来源:https://stackoverflow.com/questions/57698110/how-to-preview-pdf-using-active-storage-and-poppler