Menu

Amazon S3 batch uploading + upload stream

This is an old post from 2011. As such, it might not be relevant anymore.

It was hard to track down if these two features were possible with the latest Amazon S3 SDK, but they are and have documented them for you below.

Batch uploading

// Create Amazon S3 instance
$s3 = new AmazonS3();

// Send a file to Amazon S3
// Note we are calling batch()
$response = $s3->batch()->create_object('myBucket','myFile.jpg', array(
    'fileUpload' => fopen('myFile.jpg', 'r')
));

// Send another file to Amazon S3
$response = $s3->batch()->create_object('myBucket','myOtherFile.jpg', array(
    'fileUpload' => fopen('myOtherFile.jpg', 'r')
));

// We have batched all of the files, now send
$s3->batch()->send();

Sending a stream of data to Amazon S3

// Create Amazon S3 instance
$s3 = new AmazonS3();

// Send a file to Amazon S3
// Note we are using the 'body' parameter and not the 'fileUpload'
$response = $s3->create_object('myBucket','myFile.txt', array(
    'body' => 'Hello, I was dynamically streamed to this file.'
));