Re: how to upload a file using Amazon S3? - stream() or save() ?
| From: | l Burnerheimerton | Date: | Wed, 20 Aug 2008 12:53:08 +0000 |
| Subject: | Re: how to upload a file using Amazon S3? - stream() or save() ? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-29182@lists.php.net to get a copy of this message | ||
----- Original Message ----
From: Christian Schmidt <lists@chsc.dk>
To: l Burnerheimerton <lburnerheimerton@yahoo.com>
Cc: pear-general@lists.php.net
Sent: Tuesday, August 19, 2008 4:59:20 PM
Subject: Re: [PEAR] how to upload a file using Amazon S3? - stream() or save() ?
l Burnerheimerton wrote:
> In order to save a file to your bucket on S3, do you use Class: Services_Amazon_S3_Resource
> save() method or stream()?
>
You can save a file to S3 using the following piece of code:
$accessKeyId = '0PN5J17HBGZHT7JJ3X82';
$secretAccessKey = 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o';
$s3 = Services_Amazon_S3::getAccount($accessKeyId, $secretAccessKey);
$bucket = $s3->getBucket('mybucket');
$object = $bucket->getObject('foo.txt');
$object->data = 'lorem ipsum dolor sit amet';
$object->save();
Alternatively you can use the stream wrapper and use regular file
handling functions:
Services_Amazon_S3_Stream::register('s3',
array(
'access_key_id' => '0PN5J17HBGZHT7JJ3X82',
'secret_access_key' =>
'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o'));
file_put_contents('s3://mybucket/foo.txt', 'lorem ipsum dolor sit amet');
Christian
Christian:
Thanks for the code sample. I am uploading a PDF or TIFF file (using HTTP_UPLOAD) so the file
comes to my system as a file so I am trying to find the easiest way to simply move that file to the
amazon bucket. I am currently using HTTP_UPLOAD file->move() to move it to a system
directory. I want to move the file to S3 instead of a system directory.
Any ideas? Many thanks for your help!!