Skip to content

Commit

Permalink
Add :private config option
Browse files Browse the repository at this point in the history
Use presigned_url if S3 objects are private.
  • Loading branch information
biinari committed Apr 18, 2020
1 parent 9cfdd0e commit a70b996
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/amazon_s3.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ production:
# Folder where attachment thumbnails are stored
# thumbnails_folder: thumbnails/

# Whether objects are private, needing presigned URLs (default false)
# private: true

development:
# Copy configuration from `production` if desired

Expand Down
5 changes: 5 additions & 0 deletions lib/amazon_s3/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize
:region => nil,
:attachments_folder => nil,
:thumbnails_folder => nil,
:private => false,
}
end

Expand Down Expand Up @@ -66,6 +67,10 @@ def region
@config[:region]
end

def private?
@config[:private]
end

def attachments_folder
str = @config[:attachments_folder]
if str.present?
Expand Down
6 changes: 5 additions & 1 deletion lib/amazon_s3/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def delete(filename, target_folder = @@config.attachments_folder)

def object_url(filename, target_folder = @@config.attachments_folder)
object = self.object(filename, target_folder)
object.public_url
if @@config.private?
object.presigned_url(:get)
else
object.public_url
end
end

def get(filename, target_folder = @@config.attachments_folder)
Expand Down

0 comments on commit a70b996

Please sign in to comment.