我已经使用这个库进行 angular2 文件上传https://github.com/valor-software/ng2-file-upload https://github.com/valor-software/ng2-file-upload
现在我上传文件时收到此错误
XMLHttpRequest 无法加载http://localhost:8080/文件 http://localhost:8080/files。对预检请求的响应未通过访问控制检查:当请求的凭据模式为“include”时,响应中“Access-Control-Allow-Origin”标头的值不得为通配符“*”。起源 'http://本地主机:3000 http://localhost:3000' 因此不允许访问。 XMLHttpRequest 发起的请求的凭据模式由 withCredentials 属性控制。
Make withCredentials = false
在上传项目之前。您可以将此代码放入ngOnInit
/ constructor
or ngOnChanges
.
this.uploader.onBeforeUploadItem = (item) => {
item.withCredentials = false;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)