Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.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 4 如何使用s3下载带有Rails 4回形针的文件_Ruby On Rails 4_Amazon S3_Paperclip - Fatal编程技术网

Ruby on rails 4 如何使用s3下载带有Rails 4回形针的文件

Ruby on rails 4 如何使用s3下载带有Rails 4回形针的文件,ruby-on-rails-4,amazon-s3,paperclip,Ruby On Rails 4,Amazon S3,Paperclip,我有一个项目,上传文件附件与回形针和s3。如何让用户下载这些文件 模型 路线 resources :assets do member do get 'download' end end 控制器 def download data = open(@asset.file.url) send_data data.read, :type => data.content_type, :x_sendfile => true, :url_based_filen

我有一个项目,上传文件附件与回形针和s3。如何让用户下载这些文件

模型

路线

resources :assets do
  member do
    get 'download'
  end
end
控制器

  def download
    data = open(@asset.file.url)
    send_data data.read, :type => data.content_type, :x_sendfile => true, :url_based_filename => true
  end
错误:

AssetController下载中的OpenURI::HTTPError


403禁止

我找到了这个问题的解决办法

答复:

def download
  extension = File.extname(@asset.file_file_name)
  send_data open("#{@asset.file.expiring_url(10000, :original)}").read, filename: "original_#{@asset.id}#{extension}", type: @asset.file_content_type
end

网络上有无数的资源,这些资源涵盖了这一点。建议你先看看这些,如果你陷入困境(代码、错误等),尝试自己和帖子都要这样做。我在这方面尝试了不同的解决方案,但我并不清楚。@steveklein我提供了更多关于我所做工作的信息
def download
  extension = File.extname(@asset.file_file_name)
  send_data open("#{@asset.file.expiring_url(10000, :original)}").read, filename: "original_#{@asset.id}#{extension}", type: @asset.file_content_type
end