【问题标题】:Mount S3 folder under Heroku app在 Heroku 应用下挂载 S3 文件夹
【发布时间】:2015-02-06 10:59:29
【问题描述】:

有没有在你的 Heroku 应用下“挂载”一个资产文件夹,然后链接到 S3 存储桶这样的概念?

我有一个带有“公共”资产文件夹的节点应用程序。我想 .slugignore 我本地项目上的“公共”文件夹,将 grunt 上传到 s3 存储桶,并在启动时将代码 git 推送到 Heroku。 “public”文件夹将可见,但来自 S3 存储桶而不是 Heroku 的本地文件系统。

我查看了Heroku's docs,但(除了设置环境变量)似乎没有“自动”将您的 S3 存储桶安装到本地 Heroku /app 文件夹。

【问题讨论】:

    标签: heroku amazon-s3


    【解决方案1】:

    我不知道任何开箱即用的解决方案。但基本设置似乎触手可及。这是在路由中使用动态段并在控制器中使用重定向的第一次传递:

    在 routes.rb 中:

    get 's3/:file_key', to: 's3_redirects#show'
    

    s3_redirects_controller.rb:

    class S3RedirectsController < ApplicationController
      def show
        bucket = get_bucket
        file_key = params[:file_key]
        file_key += "." + params[:format] if params[:format].present?
        s3_file_link = RightAws::S3Interface.new(your_config_options_here).get_link(bucket, file_key, link_expiration_time)
        redirect_to s3_file_link
      end
    end
    

    显然你可以用你最喜欢的方法来代替你的 S3 文件,你必须定义 get_bucket 等等。

    这当然只会命中有效的键,否则你会得到一个“不存在这样的键”。如果您正在寻找 indexing / ls 类型的操作,当然还需要做更多的工作,但这里的基本结构应该允许您这样做,只要您有合理的方式从 S3 获取您正在寻找的数据.

    【讨论】:

      猜你喜欢
      • 2018-09-21
      • 2015-05-20
      • 1970-01-01
      • 2018-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多