小编the*_*oat的帖子

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

我正在尝试AWS s3通过向预签名 URL发出PUT 请求来上传文件。我已经在 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
      }
    });
  };
Run Code Online (Sandbox Code Playgroud)

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 }); …
Run Code Online (Sandbox Code Playgroud)

javascript amazon-s3 node.js reactjs

5
推荐指数
1
解决办法
2041
查看次数

标签 统计

amazon-s3 ×1

javascript ×1

node.js ×1

reactjs ×1