简体   繁体   中英

upload files to amazon s3 directly with php

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

我用这篇文章解决了这个问题:解决了:使用这篇文章: http//www.designedbyaturtle.co.uk/2013/direct-upload-to-s3-with-a-little-help-from-jquery/

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',
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM