Ruby on rails I';我用回形针+;S3——如何强制下载?
我当前的视图中有以下代码:Ruby on rails I';我用回形针+;S3——如何强制下载?,ruby-on-rails,ruby-on-rails-4,amazon-s3,paperclip,Ruby On Rails,Ruby On Rails 4,Amazon S3,Paperclip,我当前的视图中有以下代码: = link_to "Download", upload.upload.expiring_url, class: "btn btn-sm btn-success pull-right margin-right" 现在,这只是链接到文件并在浏览器中打开它。单击链接时如何强制下载文件?S3中的文件需要设置以下标题 Content-Disposition: attachment; filename=FILENAME.EXT Content-Type: applicatio
= link_to "Download", upload.upload.expiring_url, class: "btn btn-sm btn-success pull-right margin-right"
现在,这只是链接到文件并在浏览器中打开它。单击链接时如何强制下载文件?S3中的文件需要设置以下标题
Content-Disposition: attachment; filename=FILENAME.EXT
Content-Type: application/octet-stream
或者检查回形针选项,看看它是否可以在文件上传时完成。或者您可以在s3控制台中手动执行,一次一个文件。我最终按照另一个答案中的建议() 我在上传控制器中添加了下载url方法:
def download_url(style_name=:original)
s3 = AWS::S3.new
@bucket ||= s3.buckets[upload.bucket_name]
@bucket.objects[upload.s3_object(style_name).key].url_for(:read,
:secure => true,
:expires => 24*3600,
:response_content_disposition => "attachment; filename='#{upload_file_name}'").to_s
end
在我看来,我有:
= link_to "Download", upload.download_url