Reactjs 在React/Redux中的Cloudinary“;被CORS策略“阻止”;。请求标头字段授权

Reactjs 在React/Redux中的Cloudinary“;被CORS策略“阻止”;。请求标头字段授权,reactjs,express,cors,cloudinary,Reactjs,Express,Cors,Cloudinary,我的本地主机上的CORS有问题: Access to XMLHttpRequest at 'https://api.cloudinary.com/v1_1/*******/image/upload' from origin 'https://localhost:3000' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Header

我的本地主机上的CORS有问题:

Access to XMLHttpRequest at 'https://api.cloudinary.com/v1_1/*******/image/upload' from origin 'https://localhost:3000' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.
我与react/redux合作。下面是我添加/更改配置文件的redux操作。这段代码在我使用时有效,但不适用于https。我在server.js中编写了cors中间件。但这没用。我能用它做什么

export const addProfile = profile => {
  const formData = new FormData();
  formData.append("image", profile.avatar);
  formData.append("api_key", "********");
  formData.append("upload_preset", "********");
  formData.append("skipAuthorization", true);

  return (dispatch) => {
    axios.post('https://api.cloudinary.com/v1_1/********/image/upload',
      formData,
      { headers: { "X-Requested-With": "XMLHttpRequest" } })
      .then(res => {
        const image = res.data.secure_url;
        profile.avatar = image;
        axios
          .post("/api/profile", profile)
          .then(res => {
            console.log("res", res.data);
          })
          .catch(err =>
            console.log("err", err.response.data);
          );
      })
      .catch(err => console.log("cloundinary err =>", err))
  }
};

CORS问题与您尝试访问的域有关:

他们/您需要将您的域添加到api响应头中,或者如果您需要从localhost访问它,则需要使用通配符访问。启用后,您应该能够在api响应中看到CORS头


请参阅此处了解更多信息:

是否有可能设置了Axios全局默认值,例如授权标头或
withCredentials=true
,某处()?询问,因为这些与未签名上载选项不兼容。此外,您可能希望帖子正文中包含
文件
,而不是
图像
。响应的HTTP状态代码是什么?您可以使用浏览器devtools中的网络窗格进行检查。这是4xx还是5xx错误,而不是200 OK成功响应?看起来cloudinary不允许通过https从客户端加载文件。改为使用服务器负载