简体   繁体   English

由于cors,将图像上传到imgur失败

[英]Upload image to imgur failed because of cors

I'm trying to upload an image to imgur with js (browser) and get a CORS error:我正在尝试使用 js(浏览器)将图像上传到 imgur 并收到 CORS 错误:

Access to XMLHttpRequest at 'https://api.imgur.com/3/upload' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

But preflight request contains Access-Control-Allow-Origin header:但预检请求包含Access-Control-Allow-Origin标头: 在此处输入图片说明

The request itself:请求本身:
在此处输入图片说明

What I'm missing?我缺少什么? this is because access-control-allow-credentials set to true ?这是因为access-control-allow-credentials设置为true

问题是与他们的API文档:\\的网址是: https://api.imgur.com/3/image而不是https://api.imgur.com/3/upload为这里说: https://开头apidocs .imgur.com /#c85c9dfc-7487-4de2-9ecd-66f727cf3139

according todoc https://api.imgur.com/3/upload doesnt have necessary header ,根据文档https://api.imgur.com/3/upload没有必要的标题,

but on the right side ,the curl example use https://api.imgur.com/3/image has Access-Control-Allow-Origin header但在右侧,curl 示例使用https://api.imgur.com/3/image具有Access-Control-Allow-Origin标头

and somehow they will check your referer, which means if you are in develop mode like webpack dev mode use localhost:8000 it will always return 429 too many request exception并且他们会以某种方式检查您的引用者,这意味着如果您处于开发模式,如 webpack 开发模式使用localhost:8000它将始终返回 429 too many request异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM