带有凭据的角度文件上载(CORS)不起作用

Angular File Upload ( CORS ) with credentials is not working

本文关键字:上载 CORS 不起作用 文件      更新时间:2023-09-26

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

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

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

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

错误:

"NetworkError:401未经授权-devices.olacabs-dev.in/nootification/doUpload";doUpload 2跨来源请求被阻止:同源策略不允许读取hostname/nootification/doUpload处的远程资源。这可以通过将资源移动到同一域或启用CORS来解决。我换了一个不需要证书的API主机,这很有效。

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

我想我刚刚遇到了和你一样的问题。我通过在响应标头中将"访问控制允许凭据"设置为true来解决此问题。