Cordova/Phonegap通过javascript将图像上传到亚马逊S3

vq8itlhq  于 2023-03-13  发布在  Java
关注(0)|答案(1)|浏览(116)

请帮我解决这个问题。我似乎找不到问题所在。它看起来像是一路(获取图像,策略,签名等),直到它上传文件。它确实被亚马逊拒绝了...知道为什么吗?下面是我的上传代码:

POLICY_JSON = { "expiration": "2020-08-06T12:00:00.000Z",
          "conditions": [
                         {"bucket": "gloportalmobile"},
                         {"acl": "public-read"}                   
                       ]
                     };
var policyEncBase64 = btoa(JSON.stringify(POLICY_JSON));
var secret = "--My--Secret--Key--Here--";
var encodedSignature = b64_hmac_sha1(secret, policyEncBase64);
b64_hmac_sha1(secret, policyEncBase64);
  var s3URI = encodeURI("https://gloportalmobile.s3.amazonaws.com/"),
      policyBase64 = policyEncBase64,
      signature = encodedSignature,
      awsKey = 'My--AWS--Key--here--',
      acl = "public-read";

function upload(imageURI, fileName) {

    var deferred = $.Deferred(),
        ft = new FileTransfer(),
        options = new FileUploadOptions();

    options.fileKey = "file";
    options.fileName = fileName;
    options.mimeType = "image/jpeg";
    options.chunkedMode = false;
    options.params = {
        "key": fileName,
        "AWSAccessKeyId": awsKey,
        "acl": acl,
        "policy": policyBase64,
        "signature": signature
    };
    alert('encodedPolicy: '+policyBase64);
    alert('encodedSignature: '+signature);
    alert('imageURI '+imageURI);
    alert('s3URI '+s3URI);
    ft.upload(imageURI, s3URI,
        function (e) {
        alert('cool');
            deferred.resolve(e);
        },
        function (e) {
            alert('rejected');
            deferred.reject(e);             
        }, options);

    return deferred.promise();

}

return {
    upload: upload
}

因此,在这些警报消息中,我可以看到策略、签名、imageURI和S3 URI及其值,但仍然会抛出警报“rejected”消息。
这是因为我的策略或签名编码错误吗?或者我需要在Amazon S3中的global bucket上设置一些东西才能接受它?或者Amazon可以通过某种方式告诉我他们拒绝它的原因?
谢谢!

vwoqyblh

vwoqyblh1#

我认为应该是选项.头而不是选项.参数

相关问题