如何使用React将AWS S3存储桶连接到Web应用程序

问题描述 投票:0回答:1

因此,我试图将我的应用程序连接到我的AWS S3存储桶,而我尝试使用的代码对其他人有效,但对我却不起作用。对于我的应用程序,最佳方法是什么?

这是我尝试使用的代码:

由于某种原因,我的UpdateBucket()调用给我错误。

async UpdateBucket() {
  let bucketDataUpdate = JSON.stringify(this.state);
  const Url = "my url";

const FetchData = {
    method: "PUT",
    mode: "cors",
    cache: "no-cache",
    credentials: "omit",
    headers: { "Content-Type": "application/json" },
    body: bucketDataUpdate
  };
  await fetch(Url, FetchData)
    // .then(res => res.json())
    .then(data => console.log(data))
    .catch(err => console.log(err));
}

这里是错误:enter image description here

javascript reactjs amazon-web-services amazon-s3 bucket
1个回答
0
投票

是否缺少function关键字?

async function UpdateBucket() {
  let bucketDataUpdate = JSON.stringify(this.state);
  const Url = "my url";

const FetchData = {
    method: "PUT",
    mode: "cors",
    cache: "no-cache",
    credentials: "omit",
    headers: { "Content-Type": "application/json" },
    body: bucketDataUpdate
  };
  await fetch(Url, FetchData)
    // .then(res => res.json())
    .then(data => console.log(data))
    .catch(err => console.log(err));
}

或者是class的代码部分?

© www.soinside.com 2019 - 2024. All rights reserved.