Skip to content
Snippets Groups Projects
Commit d0b5ebc6 authored by Anusha Ranganathan's avatar Anusha Ranganathan
Browse files

Cleaned up expiry conversion to seconds

parent cd10a43f
Branches feature/320-download-v2
Tags
1 merge request!265Feature/320 download v2
Pipeline #12712 failed
......@@ -228,13 +228,14 @@ class S3StorageService
end
end
def presigned_url_for_download(bucket_name, file_key, expiry = ENV.fetch('S3_EXPIRY', 1).to_i.days)
def presigned_url_for_download(bucket_name, file_key, expiry = ENV.fetch('S3_EXPIRY', 1))
bucket = Aws::S3::Resource.new(region: ENV['S3_REGION']).bucket(bucket_name)
url_options = {
response_content_disposition: "attachment; filename=\"#{file_key}\""
}
url_options[:expires_in] = expiry.to_i if expiry.present?
# S3_EXPIRY is in days. expiry.days.to_i converts it to seconds
url_options[:expires_in] = expiry.to_i.days.to_i if expiry.present?
object = bucket.object(file_key)
object.exists? ? object.presigned_url(:get, url_options).to_s : nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment