I am using Heroku and Amazon S3, for storage.
I’m trying to make the download dialogue appear for the audio file, instead of the browser playing it.
In one of my controllers, I have:
response.content_type = 'application/octet-stream'
response.headers['Content-Disposition'] = "attachment; filename=@audio.filename"
response.headers['X-Accel-Redirect'] = @audio.encoded_file_url
render :nothing => true
@audio.encoded_file_url returns http://bucket_name.s3.amazonaws.com/uploads/19/test.mp3.
Which seems to work on my local machine. However, I am wondering if this approach will block an entire HTTP request handler, freezing the app until the download completes.
In Heroku, a HTTP request handler is one Dyno. And having several Dynos is expensive.
I’m not sure that you can rely on nginx being used (
X-Accel-Redirectis an nginx-ism) – the heroku docs imply that it’s not always used.In addition,
X-Accel-Redirectis, to my knowledge only for redirecting to files actually on the server, not for externally hosted files. Why not do a normal redirect to the S3 hosted file (using an authenticated URL if needed) ?If you need to set headers like content disposition, this can be done either at time of upload or afterwards. If you use fog to do your s3 business you could do it like this (assuming
storageis aFog::Storageobject)Note that this overwrites all the metadata – if you have other fields such as Content-Type, Cache-Control etc. then make sure to set them here or they will be lost.