diff --git a/lib/refile/s3.rb b/lib/refile/s3.rb index f21b3e4..ed1e5bd 100644 --- a/lib/refile/s3.rb +++ b/lib/refile/s3.rb @@ -40,10 +40,10 @@ class S3 # @param [Hash] s3_options Additional options to initialize S3 with # @see http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/Core/Configuration.html # @see http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3.html - def initialize(region:, bucket:, max_size: nil, prefix: nil, hasher: Refile::RandomHasher.new, **s3_options) + def initialize(region:, bucket:, max_size: nil, prefix: nil, acl: "public-read", hasher: Refile::RandomHasher.new, **s3_options) @s3_options = { region: region }.merge s3_options @s3 = Aws::S3::Resource.new @s3_options - credentials = @s3.client.config.credentials + credentials = @s3.client.config.credentials.credentials raise S3CredentialsError unless credentials @access_key_id = credentials.access_key_id @bucket_name = bucket @@ -51,6 +51,7 @@ def initialize(region:, bucket:, max_size: nil, prefix: nil, hasher: Refile::Ran @hasher = hasher @prefix = prefix @max_size = max_size + @acl = acl end # Upload a file into this backend @@ -61,9 +62,9 @@ def initialize(region:, bucket:, max_size: nil, prefix: nil, hasher: Refile::Ran id = @hasher.hash(uploadable) if uploadable.is_a?(Refile::File) and uploadable.backend.is_a?(S3) and uploadable.backend.access_key_id == access_key_id - object(id).copy_from(copy_source: [@bucket_name, uploadable.backend.object(uploadable.id).key].join("/")) + object(id).copy_from(copy_source: [@bucket_name, uploadable.backend.object(uploadable.id).key].join("/"), acl: @acl) else - object(id).put(body: uploadable, content_length: uploadable.size) + object(id).put(body: uploadable, content_length: uploadable.size, acl: @acl) end Refile::File.new(self, id) @@ -143,9 +144,10 @@ def clear!(confirm = nil) # backend directly. # # @return [Refile::Signature] + #http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Bucket.html#presigned_post-instance_method def presign id = RandomHasher.new.hash - signature = @bucket.presigned_post(key: [*@prefix, id].join("/")) + signature = @bucket.presigned_post(key: [*@prefix, id].join("/"), success_action_status: "201", acl: @acl) signature.content_length_range(0..@max_size) if @max_size Signature.new(as: "file", id: id, url: signature.url.to_s, fields: signature.fields) end @@ -154,4 +156,4 @@ def presign @bucket.object([*@prefix, id].join("/")) end end -end +end \ No newline at end of file