0

Want to download S3 Signed Video file...but instead of download its going to playing...

Using send_data S3 download

send_data open(file).read, filename: 'archive12.mp4', type: 'video/mp4', disposition: 'attachment'

Video File= "https://s3-eu-west-1.amazonaws.com/tokboxhub.mangoapps.com/46250362/2e1ad9d5-8240-41d2-82bc-38c34bf92e7e/archive.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJCPWVPHOCSAJPE5A%2F20190117%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20190117T181610Z&X-Amz-Expires=9000&X-Amz-SignedHeaders=host&X-Amz-Signature=a26d991341b5349f1f1e3afb820883b2187bc6151f395506add87cc78daa15ff"

Ankur Tripathi
  • 671
  • 9
  • 35
  • Possible duplicate of [file download link in rails](https://stackoverflow.com/questions/13164063/file-download-link-in-rails) – cherrysoft Jan 17 '19 at 19:16
  • the question is download video from from s3 using send data – Ankur Tripathi Jan 17 '19 at 19:18
  • That is clearly not the question you asked - you need to modify the title and the grammar and punctuation of the body accordingly for that to be the question. – cherrysoft Jan 18 '19 at 14:51

1 Answers1

2

You are using open(file).read. Hence it reads the file and plays it. Maybe remove the .read. Try adding the stream flag. Look at send_file too: https://api.rubyonrails.org/classes/ActionController/DataStreaming.html#method-i-send_file .

OR Use the aws-sdk maybe?

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')

If you still want to use send_data, maybe try:

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