Question

Without downloading and than sending the data in a body of the request. Is there any way how to just "stream it through"? At the moment I am limited by the memory allocated by PHP as I have to hold the content of the entire file in memory before sending it through ...

I am working on an enterprise App Store for Apple iOS apps (and android too but that is fine with a link) and they require the domain to be same as the server and the server itself is just too small for hosting so many files ... it also requires a valid SSL certificate which I have on the server.

I have tried to link directly to S3 already but it won't work, the only way to do this is to serve the files from the server, thus I have been asking about passing the file over/hiding the original location or I don't know, maybe mounting S3 as a drive?

Was it helpful?

Solution

A proxy using fpassthru needs to be done as suggested by @AD7six as follows:

$handle = @fopen('file path or in this case url to file on S3', 'rb');
header('Cache-Control: no-cache, must-revalidate'); 
header('Pragma: no-cache'); //keeps ie happy
header('Content-Disposition: attachment; filename=app.ipa');
header('Content-type: application/octet-stream');
header('Content-Length: '.$fileInfo['size']); // taken from a previous S3 API call to get object info
header('Content-Transfer-Encoding: binary');

ob_end_clean(); // apparently very important for bigger files
fpassthru($handle); // proxy stream file through your server
exit();

OTHER TIPS

Have you read the official documentation of S3?

See this answer: How to create download link for an Amazon S3 bucket's object?

There is no need to push the data through your server to send it to the client. In the case you need protected downloadable items, there is as well a way to give the download link a token that is only valid for a given amount of time.

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