From 290d78cea4850982a2843dc1a2954f0d66fe58d8 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Sun, 13 Nov 2022 05:57:10 +0000 Subject: Allow unsetting x-amz-acl S3 Permission headers (#20510) Some "S3 Compatible" storage providers (Cloudflare R2 is one such example) don't support setting ACLs on individual uploads with the `x-amz-acl` header, and instead just have a visibility for the whole bucket. To support uploads to such providers without getting unsupported errors back, lets use a black `S3_PERMISSION` env var to indicate that these headers shouldn't be sent. This is tested as working with Cloudflare R2. --- config/initializers/paperclip.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'config/initializers') diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index 26b0a2f7c..5c182ade4 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -67,6 +67,12 @@ if ENV['S3_ENABLED'] == 'true' retry_limit: 0, } ) + + if ENV['S3_PERMISSION'] == '' + Paperclip::Attachment.default_options.merge!( + s3_permissions: ->(*) { nil } + ) + end if ENV.has_key?('S3_ENDPOINT') Paperclip::Attachment.default_options[:s3_options].merge!( -- cgit From 9d039209cc0791ec09ebdbb93da4d63f815e1b07 Mon Sep 17 00:00:00 2001 From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Mon, 14 Nov 2022 04:26:49 +0000 Subject: Add `Cache-Control` header to openstack-stored files (#20610) When storing files in S3, paperclip is configured with a Cache-Control header indicating the file is immutable, however no such header was added when using OpenStack storage. Luckily Paperclip's fog integration makes this trivial, with a simple `fog_file` `Cache-Control` default doing the trick. --- config/initializers/paperclip.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'config/initializers') diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index 5c182ade4..a2285427c 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -125,6 +125,8 @@ elsif ENV['SWIFT_ENABLED'] == 'true' openstack_region: ENV['SWIFT_REGION'], openstack_cache_ttl: ENV.fetch('SWIFT_CACHE_TTL') { 60 }, }, + + fog_file: { 'Cache-Control' => 'public, max-age=315576000, immutable' }, fog_directory: ENV['SWIFT_CONTAINER'], fog_host: ENV['SWIFT_OBJECT_URL'], -- cgit