我尝试从外部 url 上传文件,但在访问外部 url 时出现 CORS 错误。
await fetch(url).then(function (res) {
response = res;
}).catch(function () {
setTimeout(() => {
this.toaster.error('Invalid URL', 'File Upload', {
positionClass: 'toast-top-right'
});
});
});
显示以下错误
从源“http://localhost:4200”获取“https://www.africau.edu/images/default/sample.pdf”的访问已被 CORS 策略阻止:没有“Access-Control-Allow” -Origin'标头存在于所请求的资源上。如果不透明响应满足您的需求,请将请求模式设置为“no-cors”以在禁用 CORS 的情况下获取资源。