Question

In my application I'm using Zend_Service_Amazon_S3 to store some big media files. When a user downloads a file, the application first copies the file to the local server and from there the file, together with some headers to force download the file, is sent to the browser.

Is there a way to let Amazon stream the file directly to the browser without having to copy the entire file to the local server? Ideally the application still can choose the name of the force downloaded file (which in many cases is not the same as the file on Amazon).

Was it helpful?

Solution

One solution is to use a reverse proxy server that proxies the request to Amazon S3 but also rewrites the response headers to change the file name and force the download.

This will eliminate the need to make a local copy of that file but the actual data transfer will still pass through your server.

I suggest looking into Nginx for this and more specifically into the proxy_pass and add_header configuration options.


Another solution would be to make a temporary copy of the file in S3 (using the PUT object copy call so you don't need to transfer it to your server) and then set the Content-Type and Content-Disposition headers on this object to force the download.

You can then stream these files directly from S3 to the client's browser but you'll need to regularly clean them up on S3 since they won't be automatically removed when the download is complete.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top