views:

823

answers:

3

Hello all,

I have a bunch of videos stored on my Amazon S3 storage. I'm working on creating a PHP script, very similar to the one here, where users can download the videos to their hard drive.

I'd like to use something like this:

<?php
$file_name = $_GET['file'];
$file_url = 'http://www.myamazons3.com/' . $file_name;
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"".$file_name."\""); 
readfile($file_url);
exit;

However, I am under the impression that this increases the bandwidth because the video will be coming through my server.

Any ideas on how I might be able to force the download of these videos, while avoiding reading it first through my own server?

Many thanks!

A: 

header('Location: ' . $file_url);

mickael9
That is a way to redirect the request, but all the headers that he outputs before 'Location' are meaningless since after the location header a new HTTP request is being generated that has no relation with the previous one (as HTTP is a stateless protocol).
Marko
When you put a file into S3 you tell it the content-type, it will work out transfer-encoding by itself, and will use the filename exactly as-is, so it will work fine.If your files aren't public on S3, then you'll need to generate the secure, time-limited URL (S3 Docs detail this...) and then redirect to that.
Greg
So, currently, when I open one of the MP4s in my S3, (in Firefox anyway), it embeds the MP4 and begins playing it. What content-type would I need to call it, and how would I do so?
Dodinas
A: 

Take a look at the S3 API Docs, and note the header values that you can set. Amazon will send these when the file is requested: http://docs.amazonwebservices.com/AmazonS3/latest/index.html?RESTObjectPUT.html (the same parameters can be sent with a POST to update an existing object)

Greg
A: 
Ben