gpt4 book ai didi

javascript - 带有凭据的 Angular 文件上传 ( CORS ) 不起作用

转载 作者:行者123 更新时间:2023-11-28 07:27:09 25 4
gpt4 key购买 nike

我正在使用 Angular 文件模块:https://github.com/danialfarid/ng-file-upload

我在上传到需要凭据的 api 时遇到困难。我正在传递“withCredentials:true”。这似乎不起作用。

我能够在没有凭据的情况下成功上传相同 API 的另一个设置。 CORS 在此 API 上正确设置,其他 GET/POST 调用 ( CORS ) 在此 API 上工作。

如果我在这里遗漏了一些东西,如果你能指导我,那就太好了。

错误:

“网络错误:401未经授权 - devices.olacabs-dev.in/notification/doUpload”; doUpload 2 跨源请求被阻止:同源策略不允许读取主机名/notification/doUpload 处的远程资源。这可以通过将资源移动到同一域或启用 CORS 来解决。我与不需要凭据的 API 主机进行了交换,并且成功了。

  $upload.upload({
url: NotificationAPI.hostName + '/notification/doUpload',
headers: {'Content-Type' : 'multipart/form-data'},
fields: fields,
file: file,
withCredentials : true,
}).

最佳答案

我想我也遇到了和你一样的问题。我通过在响应 header 中将“Access-Control-Allow-Credentials”设置为 true 解决了这个问题。

关于javascript - 带有凭据的 Angular 文件上传 ( CORS ) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29516885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com