从外部 url 以角度上传文件时发生 CORS 错误[重复]

问题描述 投票:0回答:1

我尝试从外部 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 的情况下获取资源。

javascript angular url upload cors
1个回答
-1
投票

您可以使用

mode: 'no-cors'
, 阅读api

© www.soinside.com 2019 - 2024. All rights reserved.