Is there such a concept as "mounting" an asset folder under your Heroku application, then linking it to S3 bucket?
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.
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.
1 Answers
Answers 1
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:
in 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
Obviously you can substitute your favorite method of interfacing with your S3 files, and you have to define get_bucket and so on.
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.
0 comments:
Post a Comment