angular - ng2-file-upload 访问控制来源问题

标签 angular file-upload

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

this.uploader.onBeforeUploadItem = (item) => {
  item.withCredentials = false;
}

关于angular - ng2-file-upload 访问控制来源问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42296349/

相关文章:

angular - 为什么在我从 ChangeDetectorRef 调用 detach() 时调用 ngDoCheck()?

angular - 复选框在 Angular 4 中无法正确加载

javascript - Observable 返回单个数组

javascript - Typescript 本地存储兼容性

javascript - Meteor:无法使用 CollectionFS 将图像上传到 S3

php - 无法将图像上传到服务器 ios

angular - Angular 2 中的不纯管道(pure = false)是否对我的性能不利?

ios - AFNetworking 不上传图片

Django 文件上传大小限制

javascript - 检测图像中嵌入的内容