Ruby on Rails下载S3视频文件

时间:2019-01-17 19:10:50

标签: ruby-on-rails ruby amazon-s3

1 个答案:

答案 0 :(得分:0)

您正在使用open(file).read。因此,它将读取文件并播放。也许删除.read。尝试添加stream标志。还要查看send_filehttps://api.rubyonrails.org/classes/ActionController/DataStreaming.html#method-i-send_file

还是使用aws-sdk?

require 'aws-sdk'

s3 = Aws::S3::Resource.new(
region: 'us-east-1',
access_key_id: '...',
secret_access_key: '...'
)

s3.bucket('bucket-name').object('key').get(response_target: '/path/to/file')

如果您仍然想使用send_data,请尝试:

data = open("https://s3.amazonaws.com/PATTH TO YOUR FILE") 
send_data data.read, filename: 'archive12.mp4', stream: false, type: 'video/mp4', disposition: 'attachment'