ng2-file-upload访问控制源问题 [英] ng2-file-upload access-control origin issue
问题描述
我已将此库用于angular2文件上传 https://github.com/valor -software/ng2-file-upload
I have used this library for angular2 file upload https://github.com/valor-software/ng2-file-upload
现在上传文件时出现此错误
Now I'm getting this error when I upload a file
XMLHttpRequest无法加载 http://localhost:8080/files .对预检请求的响应未通过访问控制检查:当请求的凭据模式为包括"时,响应中"Access-Control-Allow-Origin"标头的值不得为通配符"*".因此,不允许访问来源' http://localhost:3000 . XMLHttpRequest发起的请求的凭据模式由withCredentials属性控制.
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
中.
Make withCredentials = false
before uploading the item. You can put this code in ngOnInit
/ constructor
or ngOnChanges
.
this.uploader.onBeforeUploadItem = (item) => {
item.withCredentials = false;
}
这篇关于ng2-file-upload访问控制源问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!