【问题标题】:Refile upload to S3 still returns localhost upload重新上传到 S3 仍然返回 localhost 上传
【发布时间】:2015-06-01 18:03:22
【问题描述】:

我按照refile/refile 的教程,尝试使用`refile-s3 将我的照片上传到S3。但是,它仍在上传到我的本地主机。我想知道为什么??

Github 中的代码:https://github.com/chrisyeung1121/refile-example

我错过了什么吗?

【问题讨论】:

    标签: ruby-on-rails refile


    【解决方案1】:

    我运行了示例应用程序,一切正常,文件已上传到 S3。您可以在查看您的 s3 存储桶时看到这一点,应该有一个 /store 文件夹,里面有一个文件,看起来类似于:8d005532259e4abc0..... 它将与保存在数据库中的 id 相对应。在您的情况下,ID 在您的用户模型中存储为 profile_image_id。

    attachment_url 的结果返回 <img src="/attachments/store/fill/300/300/8d005532259e4abc0...../profile_image.jpg" alt="Profile image"> 可能会让人感到困惑,这使它看起来好像仍在上传到本地主机。

    refile 从 amazon s3 下载文件,动态将其修改为 300x300 并将其发送到浏览器。但是,不应该在每次加载页面时都这样做,因为它会浪费大量的处理能力。这就是需要 CDN 的地方,而 refile 旨在使用 CDN。这样处理后的图像就会被缓存,一切都会更快。

    在refile.rb 配置文件中:

    Refile.cdn_host = "https://your-dist-url.cloudfront.net"
    

    或者就我而言,我将其限制为生产:

    if Rails.env.production?
      Refile.cdn_host = "https://your-dist-url.cloudfront.net"
    end
    

    请注意,如果使用低于 0.6.0 的版本,.cdn_host 应该是 .host

    现在这应该返回类似<img src="https://your-dist-url.cloudfrond.net/attachments/store/fill/300/300/8d005532259e4abc0...../profile_image.jpg" alt="Profile image">

    您可以在官方documentation了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 2020-02-19
      • 2018-12-21
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多