【问题标题】:Rails: Refile gem (attachment_image_tag prints wrong URL)Rails:重新归档 gem(attachment_image_tag 打印错误的 URL)
【发布时间】:2016-12-21 14:26:24
【问题描述】:

我正在使用 refile gem 进行文件上传,并且我正在将文件直接上传到我的 amazon s3 公共存储桶。文件正在上传到以下 URL:

https://s3.amazonaws.com/{bucket-name}/store/6309035935359dca1ef549170e7facac9ab3553ad53946cea0bcb8335475

我正在使用 amazon cloudfront 从 s3 提供这些资产,所以上面给出的资产的 cloudfront url 是这样的:

https://{distribution-name}.cloudfront.net/store/6309035935359dca1ef549170e7facac9ab3553ad53946cea0bcb8335475

通过浏览器直接访问时,这两个网址都可以正常工作。为了在我的应用视图文件中显示这个资产,我使用了 refile gem 以下辅助函数:

attachment_image_tag(@post, :profile_img, :fill, 350, 350)

现在的问题是,这个辅助方法会打印一个类似这样的 URL:

https://{distribution-name}.cloudfront.net/attachments/5845d0a97dc77a57b5b05742a1eb26d629d7cdaa/store/fill/350/350/6309035935359dca1ef549170e7facac9ab3553ad53946cea0bcb8335475/file

由于此 URL 与上面的 cloudfront URL 不同,它不显示图像。如何强制 attachment_image_tag 函数打印正确的云端 URL?

【问题讨论】:

    标签: ruby-on-rails file-upload amazon-s3 amazon-cloudfront refile


    【解决方案1】:

    问题已解决。 github上的另一个人指出了这个问题:https://github.com/refile/refile/issues/500#issuecomment-239784247

    听起来您可能已经设置了 Cloudfront 发行版 您的 S3 存储桶作为其来源?但是,Refile 不会生成 URL 直接到 S3 上的文件(请参阅自述文件第 3 节。机架应用程序)。 因此,您需要将 Cloudfront 发行版的来源设置为 是您的应用程序的 URL。这样,文件将从 您的应用程序在第一次请求时,并由 Cloudfront 缓存 未来的请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 2014-01-15
      相关资源
      最近更新 更多