Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AWS S3通过预签名url上传返回400个错误请求_Javascript_Node.js_Reactjs_Amazon S3 - Fatal编程技术网

Javascript AWS S3通过预签名url上传返回400个错误请求

Javascript AWS S3通过预签名url上传返回400个错误请求,javascript,node.js,reactjs,amazon-s3,Javascript,Node.js,Reactjs,Amazon S3,我正试图通过向预签名的URL发出PUT请求,将文件上载到AWS s3。我已经在s3仪表板上配置了CORS 反应码 const submit = async () => { const response = await axios.get("http://localhost:8080/api/upload"); console.log(response.data); const upload = await axios.put(response.data.url,

我正试图通过向预签名的URL发出PUT请求,将文件上载到
AWS s3
。我已经在s3仪表板上配置了CORS

反应码

  const submit = async () => {
    const response = await axios.get("http://localhost:8080/api/upload");
    console.log(response.data);
    const upload = await axios.put(response.data.url, file, {
      headers: {
        "Access-Control-Allow-Origin": "*",
        "Content-Type": file.type
      }
    });
  };
Node.js代码

const s3 = new AWS.S3({
  accessKeyId: config.aws.accessKeyId,
  secretAccessKey: config.aws.secretAccessKey
});
app.get("/api/upload", (req, res) => {
  const key = `${uuid()}.jpeg`;
  s3.getSignedUrl(
    "putObject",
    {
      Bucket: "bucket-name",
      ContentType: "image/jpeg",
      Key: key
    },
    (err, url) => {
      res.status(200).json({ key, url });
    }
  );
});
当我尝试向预签名的URL发出
PUT
请求时,我遇到了下一个错误:

放 400(错误请求)createError.js:17未捕获(承诺中)错误: 请求失败,状态代码为400 在createError(createError.js:17) 结算时(结算js:19) 在XMLHttpRequest.handleLoad(xhr.js:60)


创建s3 instance replace region和bucket区域的方法:

AWS.config.update({region: 'REGION'});

const s3 = new AWS.S3({
  apiVersion: '2006-03-01',
  accessKeyId: keys.accessKeyId,
  secretAccessKey: keys.secretAccessKey
});

400错误请求
有几个原因。您需要捕获附带的响应主体以进行解释。您解决过这个问题吗?我也遇到了@michaelsqlbot指出的同样的问题,通过观察身体的反应来解决。我得到了一个“AuthorizationQueryParametersError”。对我来说,同样的错误也存在,它通过