简体   繁体   中英

Upload files to Amazon using PlUpload and Expiring Amazon S3 Link

I got plupload working directly to Amazon S3 with this sample code.I got the Direct Browser to S3 Upload using temporary credentials.

Now I need to generate expiring Amazon S3 Link and using those temporary credentials need to implement the Plupload . ie I need to mix both the cases mentioned above.So I generate the url and put it as the url in the following code.

<script type="text/javascript">
$(function() {
$("#uploader").plupload({
    runtimes : 'flash,silverlight',
    url : 'TEMPORARY URL',
    max_file_size : '10mb',

    multipart: true,
    multipart_params: {
        'key': '${filename}', 
        'Filename': '${filename}',
        'acl': 'public-read',
        'Content-Type': 'image/jpeg',
        'success_action_status': '201'
    },
    file_data_name: 'file',
    multiple_queues: true,
    filters : [
        {title : "JPEG files", extensions : "jpg"}
    ],
    flash_swf_url : '../../js/plupload.flash.swf',
    silverlight_xap_url : '../../js/plupload.silverlight.xap'
});
});
</script>

Generate Expiring Amazon S3 Link

<?php 
$S3_KEY='S3 Key Here';
$S3_SECRET='S3 Secret Here';
$S3_BUCKET='/uploadtestbucket';

$EXPIRE_TIME=(60 * 5); // 5 minutes
$S3_URL='http://s3.amazonaws.com';

$objectName='/' . $_GET['name'];

$mimeType=$_GET['type'];
$expires = time() + $EXPIRE_TIME;
$amzHeaders= "x-amz-acl:public-read";
$stringToSign = "PUT\n\n$mimeType\n$expires\n$amzHeaders\n$S3_BUCKET$objectName";
$sig = urlencode(base64_encode(hash_hmac('sha1', $stringToSign, $S3_SECRET, true)));

$url = urlencode("$S3_URL$S3_BUCKET$objectName?    AWSAccessKeyId=$S3_KEY&Expires=$expires&Signature=$sig");

echo $url;
?>

But I am getting this error

IO error. Error #2032

My reference links are

What is the mistake in my code??

Check your policy, maybe its not setup properly and you are sending "extra inputs". Try using your browser's console and switch to Network panel - find the http request made to amazon and check response, it will show you the error.

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