Created
September 3, 2019 15:46
-
-
Save waclock/547ec49be61f4282de4e779f9caa5fae to your computer and use it in GitHub Desktop.
This file contains 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
require "shrine" | |
if Rails.env.production? | |
require "shrine/storage/s3" | |
s3_options = { | |
bucket: ENV["AWS_BUCKET_NAME"], | |
region: ENV["AWS_REGION"], | |
access_key_id: ENV["AWS_ACCESS_KEY_ID"], | |
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"], | |
} | |
Shrine.storages = { | |
cache: Shrine::Storage::S3.new(prefix: "#{ENV['AWS_WEBAPP_FOLDER']}_cache", **s3_options), | |
store: Shrine::Storage::S3.new(prefix: ENV['AWS_WEBAPP_FOLDER'], **s3_options), | |
public_cache: Shrine::Storage::S3.new("public", prefix: "#{ENV['PUBLIC_AWS_WEBAPP_FOLDER']}_cache", **s3_options), | |
public_store: Shrine::Storage::S3.new("public", prefix: ENV['PUBLIC_AWS_WEBAPP_FOLDER'], **s3_options), | |
} | |
else | |
require "shrine/storage/file_system" | |
Shrine.storages = { | |
cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"), | |
store: Shrine::Storage::FileSystem.new("public", prefix: "uploads"), | |
public_cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"), | |
public_store: Shrine::Storage::FileSystem.new("public", prefix: "uploads"), | |
} | |
end | |
Shrine.plugin :default_url_options | |
Shrine.plugin :activerecord | |
Shrine.plugin :backgrounding | |
Shrine.plugin :logging | |
Shrine.plugin :determine_mime_type, analyzer: :mime_types | |
Shrine.plugin :cached_attachment_data | |
Shrine.plugin :restore_cached_data | |
if Rails.env.production? | |
Shrine.plugin :presign_endpoint, presign_options: -> (request) { | |
# Uppy will send the "filename" and "type" query parameters | |
filename = request.params["filename"] | |
type = request.params["type"] | |
{ | |
content_disposition: "inline; filename=\"#{filename}\"", # set download filename | |
content_type: type, # set content type (defaults to "application/octet-stream") | |
content_length_range: 0..(10*1024*1024), # limit upload size to 10 MB | |
} | |
} | |
else | |
Shrine.plugin :upload_endpoint | |
end | |
Shrine::Attacher.promote { |data| PromoteJob.perform_async(data) } | |
Shrine::Attacher.delete { |data| DeleteJob.perform_async(data) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment