简体   繁体   English

使用 PlUpload 和 Expiring Amazon S3 Link 将文件上传到 Amazon

[英]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.我使用示例代码将 plupload 直接工作到 Amazon S3。我使用临时凭证获得了Direct Browser to S3 Upload

Now I need to generate expiring Amazon S3 Link and using those temporary credentials need to implement the Plupload .现在我需要生成过期的 Amazon S3 链接并使用这些临时凭证来实现 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.即我需要混合上面提到的两种情况。所以我生成了 url 并将其作为 url 放在下面的代码中。

<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生成过期的 Amazon S3 链接

<?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错误 #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.尝试使用浏览器的控制台并切换到网络面板 - 找到向亚马逊发出的 http 请求并检查响应,它会显示错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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