Skip to content

Commit 7dcc1b7

Browse files
committed
acl & success_action_status options + PR18
1)add acl option to initialise method and use in available calls defaults to ‘public-read’ so backwards compatible, but enables people to make private as desired. 2) also included deprecation fix from PR refile#18 3) added success_action_status: 201 to presign method to fix firefox xml parse error: XML Parsing Error: no element found Location: moz-nullprincipal:{28d28eb9-bcef-f842-8355-54e833de9cd1} Line Number 1, Column 1:
1 parent 78a74b6 commit 7dcc1b7

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/refile/s3.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ class S3
4040
# @param [Hash] s3_options Additional options to initialize S3 with
4141
# @see http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/Core/Configuration.html
4242
# @see http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3.html
43-
def initialize(region:, bucket:, max_size: nil, prefix: nil, hasher: Refile::RandomHasher.new, **s3_options)
43+
def initialize(region:, bucket:, max_size: nil, prefix: nil, acl: "public-read", hasher: Refile::RandomHasher.new, **s3_options)
4444
@s3_options = { region: region }.merge s3_options
4545
@s3 = Aws::S3::Resource.new @s3_options
46-
credentials = @s3.client.config.credentials
46+
credentials = @s3.client.config.credentials.credentials
4747
raise S3CredentialsError unless credentials
4848
@access_key_id = credentials.access_key_id
4949
@bucket_name = bucket
5050
@bucket = @s3.bucket @bucket_name
5151
@hasher = hasher
5252
@prefix = prefix
5353
@max_size = max_size
54+
@acl = acl
5455
end
5556

5657
# Upload a file into this backend
@@ -61,9 +62,9 @@ def initialize(region:, bucket:, max_size: nil, prefix: nil, hasher: Refile::Ran
6162
id = @hasher.hash(uploadable)
6263

6364
if uploadable.is_a?(Refile::File) and uploadable.backend.is_a?(S3) and uploadable.backend.access_key_id == access_key_id
64-
object(id).copy_from(copy_source: [@bucket_name, uploadable.backend.object(uploadable.id).key].join("/"))
65+
object(id).copy_from(copy_source: [@bucket_name, uploadable.backend.object(uploadable.id).key].join("/"), acl: @acl)
6566
else
66-
object(id).put(body: uploadable, content_length: uploadable.size)
67+
object(id).put(body: uploadable, content_length: uploadable.size, acl: @acl)
6768
end
6869

6970
Refile::File.new(self, id)
@@ -143,9 +144,10 @@ def clear!(confirm = nil)
143144
# backend directly.
144145
#
145146
# @return [Refile::Signature]
147+
#http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Bucket.html#presigned_post-instance_method
146148
def presign
147149
id = RandomHasher.new.hash
148-
signature = @bucket.presigned_post(key: [*@prefix, id].join("/"))
150+
signature = @bucket.presigned_post(key: [*@prefix, id].join("/"), success_action_status: "201", acl: @acl)
149151
signature.content_length_range(0..@max_size) if @max_size
150152
Signature.new(as: "file", id: id, url: signature.url.to_s, fields: signature.fields)
151153
end
@@ -154,4 +156,4 @@ def presign
154156
@bucket.object([*@prefix, id].join("/"))
155157
end
156158
end
157-
end
159+
end

0 commit comments

Comments
 (0)