Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to pass s3_client_options for s3 compatible object storage #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/mini_paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def config
keep_old_files: false,
read_timeout: 60,
logger: Logger.new($stdout),
s3_client_options: {},
)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/mini_paperclip/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Config < Struct.new(
:s3_bucket_name,
:s3_acl,
:s3_cache_control,
:s3_client_options,
:interpolates,
:keep_old_files,
:read_timeout,
Expand Down
8 changes: 4 additions & 4 deletions lib/mini_paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Storage
class S3 < Base
def write(style, file)
debug("writing by S3 to bucket:#{@config.s3_bucket_name},key:#{s3_object_key(style)}")
Aws::S3::Client.new.put_object(
Aws::S3::Client.new(@config.s3_client_options).put_object(
acl: @config.s3_acl,
cache_control: @config.s3_cache_control,
content_type: @attachment.content_type,
Expand All @@ -26,7 +26,7 @@ def host
end

def exists?(style)
Aws::S3::Client.new.head_object(
Aws::S3::Client.new(@config.s3_client_options).head_object(
bucket: @config.s3_bucket_name,
key: s3_object_key(style),
)
Expand All @@ -42,7 +42,7 @@ def push_delete_file(style)
def do_delete_files
return if @deletes.empty?
debug("deleting by S3 to bucket:#{@config.s3_bucket_name},objects:#{@deletes}")
Aws::S3::Client.new.delete_objects(
Aws::S3::Client.new(@config.s3_client_options).delete_objects(
bucket: @config.s3_bucket_name,
delete: {
objects: @deletes,
Expand All @@ -54,7 +54,7 @@ def do_delete_files
def open(style)
Tempfile.new(['MiniPaperclip::Storage::S3']).tap do |response_target|
response_target.binmode
Aws::S3::Client.new.get_object(
Aws::S3::Client.new(@config.s3_client_options).get_object(
bucket: @config.s3_bucket_name,
key: s3_object_key(style),
response_target: response_target,
Expand Down