React JS使用API上传图像
因此,我正在尝试使用React JS Ant设计上传组件上传文件,现在我面临的问题是,每当我尝试提交图像时,我都会收到以下错误:
访问'https://freeimage.host/api /1/upload'从原始''http:// localhost:3000'被CORS策略阻止:没有“访问control-wall-allow-origin”标题在请求的资源上存在。如果不透明的响应满足您的需求,请将请求模式设置为“无库”,以通过禁用CORS来获取资源。
/I.sstatic.net/si1nb.png“ alt =”在此处输入图像描述”>
So I am trying to upload a file using React Js ant design upload component now the issue I am facing is that whenever I try to submit an image I received the following error:
Access to fetch at 'https://freeimage.host/api/1/upload' 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.
I have attached the code that I have written to upload and handle file submissions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将尝试将标题添加到您的Handlesubmission Arrow功能中的获取并串起身体。
I would try adding headers to the fetch inside your handleSubmission arrow function and stringify the body.
如果您使用后端作为 Node js,请添加以下代码
If you are using your backend as node js add following code to it