The POST
operation adds an object to a specified bucket using HTML forms. POST is an alternate
form of PUT
that enables browser-based uploads as a way of putting objects in buckets.
Parameters that are passed to PUT
via HTTP headers are instead passed as form fields to
POST
in the multipart/form-data
encoded message body. You must have
WRITE
access on a bucket to add an object to it. Amazon S3 never stores partial objects: if
you receive a successful response, you can be confident the entire object was stored.
Access
public
Parameters
Parameter |
Type |
Required |
Description |
---|---|---|---|
|
Required |
The name of the bucket to use. |
|
|
Optional |
The point in time when the upload form field should expire. The default value is |
|
|
Optional |
An associative array of parameters that can have the following keys:
|
Returns
Type |
Description |
---|---|
An array of fields that can be converted into markup. |
Examples
Generate the parameters for a browser-based POST upload.
This example shows how to construct the data object that is then used to generate HTML.
$upload = new S3BrowserUpload(); // Generate the parameters for the upload. $html_parameters = $upload->generate_upload_parameters('my-upload-bucket', '15 minutes', array( // Set permissions to private. 'acl' => AmazonS3::ACL_PRIVATE, // Set various HTTP headers on the uploaded file. 'Content-Disposition' => 'attachment; filename=information.txt', 'Content-Encoding' => 'gzip', 'Content-Type' => '^text/', 'Expires' => gmdate(DATE_RFC1123, strtotime('January 1, 1970, midnight GMT')), // Format for the HTTP Expires header // The S3 Key to upload to. ${filename} is an S3 variable that equals the name of the file being uploaded. // We're also using PHP's built-in Filter extension in this example. 'key' => '^user/' . filter_var($_POST['user_id'], FILTER_VALIDATE_INT) . '/${filename}', // Where should S3 redirect to after the upload completes? The current page. 'success_action_redirect' => S3BrowserUpload::current_uri(), // Status code to send back on success. This is primarily to work around issues in Adobe® Flash®. 'success_action_status' => 201, // Use reduced redundancy storage. 'x-amz-storage-class' => AmazonS3::STORAGE_REDUCED )); <form action="<?= $html_parameters['form']['action'] " method="<?= $html_parameters['form']['method'] " enctype="<?= $html_parameters['form']['enctype'] "> <? foreach ($html_parameters['inputs'] as $name => $value): <input type="hidden" name="<?= $name; " value="<?= $value; "> <? endforeach; <input type="file" name="file"> <input type="submit" name="upload" value="Upload"> </form>
See Also
Source
Method defined in extensions/s3browserupload.class.php | Toggle source view (81 lines) | View on GitHub