Angular 带凭据的文件上传 (CORS) 无法正常工作

Angular File Upload ( CORS ) with credentials is not working

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

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

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

上工作

如果我在这里遗漏了什么,如果你能指导我,那就太好了。

错误:

"NetworkError: 401 Unauthorized - devices.olacabs-dev.in/notification/doUpload"; doUpload 2 跨源请求被阻止:同源策略不允许读取位于 hostname/notification/doUpload 的远程资源。这可以通过将资源移动到同一域或启用 CORS 来解决。我与不需要凭据的 API 主机进行了交换,并且有效。

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

我想我刚刚遇到了和你一样的问题。我通过在响应 headers.

中将 'Access-Control-Allow-Credentials' 设置为 true 来解决它