1

我正在使用角度文件模块: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 跨域请求被阻止:同源策略不允许读取主机名/通知/doUpload 处的远程资源。这可以通过将资源移动到同一域或启用 CORS 来解决。我与不需要凭据的 API 主机进行了交换,并且有效。

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

4

1 回答 1

0

我想我刚刚遇到了和你一样的问题。我通过在响应标头中将“Access-Control-Allow-Credentials”设置为 true 来解决它。

于 2015-04-17T15:34:02.003 回答