Reputation: 564
solved: using this post : http://www.designedbyaturtle.co.uk/2013/direct-upload-to-s3-with-a-little-help-from-jquery/
edit: I'm looking for a way to directly upload a big zip file from client side to amazon s3 without first uploading it to my server
I'm using a small server for my web application with laravel framework I have some users trying to upload big files to my servr (around 300-400m), and my server is to weak and my bandwidth is to low for the user to be able to finish uploading.
I want the file to be uploaded directly to amazon s3, from browsing around i dont think this can be dont with laravel sdk for amazon
I installed the official sdk and I'm trying to do it like suggested in this post uploading posted file to amazon s3
but not rally sure how to actually send my file to amazon s3, what should i put instad of 'string of your file here':
$result = $client->upload(
'BUCKET HERE',
'OBJECT KEY HERE',
'STRING OF YOUR FILE HERE',
'public-read' // public access ACL
);
im getting my file like this :
$myFile = Input::file('file');
putting $myfile instead of 'string of your file here' doesnt work
Upvotes: 5
Views: 5105
Reputation: 564
I solved the problem using this post: solved: using this post : http://www.designedbyaturtle.co.uk/2013/direct-upload-to-s3-with-a-little-help-from-jquery/
Upvotes: 5
Reputation: 3726
You can upload files directly from the client side to S3, but it's a security risk as you can't validate the file, plus giving anyone access to your S3 buckets is just generally a bad idea. I would still look at uploading via your Laravel application.
All files uploaded to PHP are stored on your server, most likely in the /tmp
directory for Linux and Mac machines. There's no way to avoid that, the file needs to be stored somewhere. You obtain an object representing the file using Input::file('file')
.
The file is an instance of Symfony\Component\HttpFoundation\File\UploadedFile
, which exposes a getRealPath()
method. We can then use fopen()
to read the contents of the file as a string. So to upload it to S3, use:
$client->upload(
'bucket',
'key',
fopen($file->getRealPath(), 'r'),
'public-read',
);
Upvotes: 1