Skip to content
Merged
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
16 changes: 13 additions & 3 deletions app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ def show
end

def download
send_data URI.parse(@blob.url).read,
type: "#{@blob.content_type}",
disposition: "attachment; filename=#{@blob.filename.to_s}"
object = ActiveStorage::Blob.service.bucket.object(@blob.key)
content_disposition = ActionDispatch::Http::ContentDisposition.format(
disposition: "attachment",
filename: @blob.filename.sanitized
)
presigned_url = object.presigned_url(
:get,
expires_in: ActiveStorage.service_urls_expire_in.to_i,
response_content_disposition: content_disposition
)

expires_in ActiveStorage.service_urls_expire_in
redirect_to presigned_url, allow_other_host: true
end

def static
Expand Down
Loading