AWS S3浏览器上载:无效的策略无效的JSON错误

时间:2016-05-29 01:15:00

标签: javascript amazon-web-services amazon-s3

我想直接从浏览器上传文件到S3机器,绕过发送到我的服务器。

我已阅读amazon here的相关帖子,并将完整的javascript示例发布为答案here。但是当我尝试javascript解决方案时,我收到以下错误:

var policy = {s3PolicyBase64: "eyJleHBpcmF0aW9uIjoiMjAxNi00MS0yOVQxOjI0OjI4WiIsIm…sWyJzdGFydHMtd2l0aCIsIiRDb250ZW50LVR5cGUiLCIiXV19", s3Signature: "JlZ6UdDWVhHoeiu5urdTtQupkO0=", s3Key: "AKIAJ6LFZZBY24MBQ4GA"}

在服务器端,我生成了我的政策,并使用下面的s3policy package修改:包含已签名的政策示例对其进行签名:

  var fd = new FormData();
  // Populate the Post paramters.
  fd.append('key', key);
  fd.append('Content-Type', content_type);
  fd.append('AWSAccessKeyId', policy["s3Key"]);
  fd.append('acl', 'private');
  fd.append('success_action_redirect', "https://attachments.me/upload_callback")
  fd.append('policy', policy["s3PolicyBase64"])
  fd.append('signature',policy["s3Signature"])
  // This file object is retrieved from a file input.
  fd.append('file', $('#file_'+id)[0].files[0]);

  var xhr = new XMLHttpRequest();

  xhr.upload.addEventListener("progress", uploadProgress, false);
  xhr.addEventListener("load", uploadComplete, false);
  xhr.addEventListener("error", uploadFailed, false);
  xhr.addEventListener("abort", uploadCanceled, false);

  xhr.open('POST', dest_url, true); //MUST BE LAST LINE BEFORE YOU SEND 

  xhr.send(fd);

以下是我在浏览器中用来生成表单并提交帖子的代码:

{"expiration":"2016-41-29T1:24:28Z",
"conditions":[{"bucket":"intellilease-docs"},["eq","$key","uploads/OK/Stephens/"],{"acl":"private"},["content-length-range",0,null],["starts-with","$Content-Type",""]]}

我经历了双重检查输出的缓慢过程,但我对导致无效策略错误的原因一无所知。这是我的策略的base64解码版本,也许有人可以识别它的无效内容。

point1:(5;100)
point2: (9;17)
point3: (12;17)

感谢任何帮助或建议!

0 个答案:

没有答案