【发布时间】:2019-01-15 17:20:57
【问题描述】:
我目前使用的是 Rails 5.2.2。 我正在尝试在 2 个模型之间复制一张图像。所以我想要 2 个文件,以及 blob 和附件中的 2 个条目。 我的原始对象/图像在 AWS S3 上。
我的原始模型是photo,我的目标模型是image。
我试过了:
image.file.attach(io: open(best_photo.full_url), filename: best_photo.filename, content_type: best_photo.content_type)
full_url 是 photo.rb 中添加的方法:
include Rails.application.routes.url_helpers
def full_url
rails_blob_path(self.file, disposition: "attachment", only_path: true)
end
我收到这个错误,好像找不到文件:
没有这样的文件或目录@rb_sysopen - /rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBHZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--2f865041b01d2f2c323a20879a855f25f231289d/881dc909-88ab-43b6-8148-5adbf888b399.jpg?disposition=attachment P>
我尝试了其他不同的方法,例如(此方法在使用 image_tag() 显示图像时使用并且可以正常工作:
def download_variant(version)
variant = file_variant(version)
return rails_representation_url(variant, only_path: true, disposition: "attachment")
end
同样的错误。
我已验证并且该文件存在于 S3 服务器上。 我错过了什么?
谢谢。
【问题讨论】:
标签: ruby-on-rails copy rails-activestorage