在Heroku应用下挂载S3文件夹 [英] Mount S3 folder under Heroku app

查看:113
本文介绍了在Heroku应用下挂载S3文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有这样一个概念,在您的Heroku应用程序下挂载一个资产文件夹,然后将其链接到S3存储桶?

Is there such a concept as "mounting" an asset folder under your Heroku application, then linking it to S3 bucket?

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

I have a node app with a "public" asset folder. I'd like to .slugignore the "public" folder on my local project, have grunt upload to s3 bucket, and git push the code to Heroku when it starts up. The "public" folder will be visible, but sourced from the S3 bucket instead of Heroku's local file system.

我查看了 Heroku的文档,但是(除了设置env变量)没有automagic,它似乎将你的S3存储桶挂载到你当地的Heroku / app文件夹中。 / p>

I looked at Heroku's docs but (besides setting the env variables) there's no "automagic" that appears to mount your S3 bucket to your local Heroku /app folder.

推荐答案

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

I'm not aware of any out of the box solution. But a basic setup seems within reach. Here's a first pass using a dynamic segment in the route and a redirect in the controller:

位于routes.rb中:

in routes.rb:

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



s3_redirects_controller.rb:

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等等。

Obviously you can substitute your favorite method of interfacing with your S3 files, and you have to define get_bucket and so on.

当然这只会碰到有效的键,否则就会得到不存在这样的键。如果您正在寻找索引/ ls类型的动作,当然还有更多需要完成的工作,但只要您有合理的方法从S3获取您要查找的数据,这里的基本结构应该允许您这样做。

This of course only hits valid keys, you'll get a "no such key exists" otherwise. If you're looking for indexing / ls type actions, of course more needs to be done, but the basic structure here should allow you to do that as long as you have a reasonable way to get the data you're looking for from S3.

这篇关于在Heroku应用下挂载S3文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆