我已将此库用于 angular2 文件上传 https://github.com/valor-software/ng2-file-upload
现在我在上传文件时遇到这个错误
XMLHttpRequest cannot load http://localhost:8080/files. Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:3000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
最佳答案
在上传项目之前设置withCredentials = false
。您可以将此代码放在 ngOnInit
/constructor
或 ngOnChanges
中。
this.uploader.onBeforeUploadItem = (item) => {
item.withCredentials = false;
}
关于angular - ng2-file-upload 访问控制来源问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42296349/