ng2-file-upload访问控制源问题 [英] ng2-file-upload access-control origin issue

查看:46
本文介绍了ng2-file-upload访问控制源问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将此库用于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/constructorngOnChanges中.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆