Last active
September 27, 2020 19:21
-
-
Save ericboehs/59ff72b7beeb2724a0979247d0fe7541 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# This file lives in lib/active_storage/service/s3_directory_service.rb. | |
require 'aws-sdk-s3' | |
require 'active_storage/service/s3_service' | |
require 'active_support/core_ext/numeric/bytes' | |
module ActiveStorage | |
class Service | |
class S3DirectoryService < S3Service | |
def proxy_url(url) | |
return url unless ENV['ATTACHMENT_HOST'] | |
URI.join(ENV['ATTACHMENT_HOST'], URI(url).path).to_s | |
end | |
def url(key, **) | |
instrument :url, key: key do |payload| | |
payload[:url] = proxy_url object_for(key).public_url | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file lives in config/storage.yml. | |
test: | |
service: Disk | |
root: <%= Rails.root.join("tmp/storage") %> | |
local: | |
service: Disk | |
root: <%= Rails.root.join("storage") %> | |
amazon: | |
service: S3Directory | |
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %> | |
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %> | |
region: <%= ENV['AWS_S3_REGION'] %> | |
bucket: <%= ENV['AWS_BUCKET'] %> | |
upload: | |
cache_control: 'public, max-age=31536000' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment