带有签名的响应403与使用presignurl s3不匹配,无法解析

时间:2019-03-01 04:29:42

标签: amazon-s3

我遇到一些问题,该问题在上传我的图像时收到签名不匹配错误。寻求所有人查看我的代码,是否有任何解决方案可以解决。

// image is filePath like file://data/storage/0/...jpg
export const uploadImageToS3 = async (image, signS3, mime) => {
  let file = {
    uri: image,
    type: "image/png"
  };
  const data = await uploadFile(file, signS3.uploadUrl, mime,);
  return data;
};

const uploadFile = (file, signedRequest, mime) => {
  const xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {
      if (xhr.status === 200) {
        console.log("Image successfully uploaded to S3");
        console.log(xhr);
      } else {
        console.log("Error while sending the image to S3");
        console.log(xhr);
      }
    }
    console.log(xhr);
  };
  xhr.open("PUT", signedRequest);
  xhr.setRequestHeader("X-Amz-ACL", "public-read");
  xhr.setRequestHeader("Content-Type", mime);
  xhr.send(file);
};

以下是错误消息:

<Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>

我尝试了setHeader Content-type,x-amz-acl,但仍显示错误。响应为空代表成功发送后的内容

0 个答案:

没有答案