I'm attempting to access files on my S3 server via my rails app. Currently the app is able to create a presigned_url
through the aws-sdk v2 gem and then redirect to display the file (I've mostly been using images as the file). This all works very well but rather than simply displaying the file in the browser, I would REALLY like to trigger an automatic download of that file.
As it stands with the redirect, my code is as follows:
def get
asset = current_user.assets.find_by_id(params[:id])
if asset
s3 = Aws::S3::Resource.new
bucketlink = s3.bucket(ENV['S3_BUCKET_NAME']).object(asset.uploaded_file.path).presigned_url(:get, expires_in: 3600)
redirect_to bucketlink
else
flash[:error]="Don't be cheeky! Mind your own assets"
redirect_to assets_path
end
end
Can anyone give me a clue as to how I can trigger a download of this file? Many thanks in advance.