Ruby on Rails AWS S3下载URL [英] Ruby on Rails AWS S3 Download URL
本文介绍了Ruby on Rails AWS S3下载URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为用户形成一个URL链接,以便当用户单击链接时,它会迫使他们下载AWS S3对象?
How can I form a url link for a user so that when the user clicks on the link, it forces them to download the AWS S3 object?
我已经看到了这两种解决方案:使用send_file从Amazon S3下载文件吗?,他们似乎引用了旧的AWS S3 v1 SDK,并且在v2 AWS S3中似乎没有url_for SDK.
I've seen these two solutions: Using send_file to download a file from Amazon S3? and Using send_file to download a file from Amazon S3? however, they seem to reference an old AWS S3 v1 SDK and there does not seem to be a url_for in the v2 AWS S3 SDK.
谢谢.
推荐答案
最后使用以下代码片段进行了解决.希望这对其他人有帮助.
Ended up using the following code snippet to solve. Hope this helps others.
presigner = Aws::S3::Presigner.new
url = presigner.presigned_url(:get_object, #method
bucket: ENV['S3_BUCKET'], #name of the bucket
key: s3_key, #key name
expires_in: 7.days.to_i, #time should be in seconds
response_content_disposition: "attachment; filename=\"#{filename}\""
).to_s
这篇关于Ruby on Rails AWS S3下载URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文