Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails I';我用回形针+;S3——如何强制下载?_Ruby On Rails_Ruby On Rails 4_Amazon S3_Paperclip - Fatal编程技术网

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