[英]Display PDF stored on Amazon S3 with Rails
Im trying to display an attached pdf which is stored on Amazon S3 on the model's show
view, but I can't get it to work.我试图在模型的
show
视图中show
存储在 Amazon S3 上的附加 pdf,但我无法让它工作。 So far my best attempt was to get the uploaded file's url on s3 like this :到目前为止,我最好的尝试是像这样在 s3 上获取上传文件的 url:
#controller.rb
@key = upload.file.service_url
which successfully gets the URL of the file, and display it with iframe in the view.它成功获取了文件的 URL,并在视图中使用 iframe 显示它。 Which sadly doesn't work.
可悲的是,这不起作用。
#view.html.erb
<iframe src=" <% @key %> " width="100%" height="500px">
It produces this:它产生这个:
My Upload
model:我的
Upload
模型:
class Upload < ApplicationRecord
belongs_to :user
has_one_attached :file
end
Thanks a lots非常感谢
Your view.html.erb should be like this你的 view.html.erb 应该是这样的
#view.html.erb
<iframe src=<%= @key %> width="100%" height="500px"></iframe>
This (" <% @key %> ") is a string for rails basically这个 (" <% @key %> ") 基本上是一个用于 rails 的字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.