问题描述
我有一个React Web应用程序,需要给定我的AWS访问ID和密钥,才能对我的S3存储桶进行API调用。但是,我不断收到错误消息。
动作和减速器位于state/app.js
:
import axios from 'axios';
const initialState = {
lrc: '',};
const config = () => (
{
headers: {
AccessKey: `${process.env.S3_KEY_ID}`,SecretKey: `${process.env.S3_SECRET}`,},}
);
const GET_LRC = 'GET_LRC';
export const getLrc = (url) => (dispatch) => {
axios.get(url,config())
.then((res) => {
dispatch({
type: GET_LRC,payload: parseLrc(res.data),});
})
.catch((err) => console.log(err.response.data));
};
...
这是我的错误:
Access to XMLHttpRequest at 'https://s3.amazonaws.com/<S3_BUCKET_NAME>/<file>' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' he
我尝试在我的存储桶上设置CORS策略,以允许所有CORS来源,但尚未解决。另外,我也不确定我的授权标头是否正确。我想我需要创建一个签名(https://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html),但我也被困在那里。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)