【发布时间】:2021-05-30 02:31:02
【问题描述】:
import imageToBase64 from 'image-to-base64';
...
formatImageToBase64 = () => {
imageToBase64("https://example.s3.ap-southeast-1.amazonaws.com/images/image1") // Path to the image
.then(
(response) => {
console.log(response);
}
)
.catch(
(error) => {
console.log(error);
}
)
}
当我运行这个函数时,出现如下错误。
Access to fetch at 'example.s3.ap-southeast-1.amazonaws.com/images/image1?AWSAccessKeyId=qwertyuip12344&Expires=1664366635&Signature=aoqogfjfj3%2Foofofol%3D' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
我检查了我的 S3 设置,但似乎没有问题。
【问题讨论】:
-
我会更深入地了解 AllowedOrigins,因为我很确定 localhost 不是您想要的
标签: reactjs amazon-web-services amazon-s3 cors