Issue with ng2-file-upload server access release

I used this library to download the angular2 file https://github.com/valor-software/ng2-file-upload

Now I get this error when uploading a file

XMLHttpRequest cannot load http: // localhost: 8080 / files . The response to the preliminary check request does not pass the access control check: the value of the "Access-Control-Allow-Origin" header in the response should not be a wildcard "*" if the request credential mode is set to include. Therefore, the origin of ' http: // localhost: 3000 ' is not allowed. XMLHttpRequest-initiated request credential mode is controlled by the withCredentials attribute.

+8
source share
3 answers

Do withCredentials = falsebefore loading the item. You can put this code in ngOnInit/ constructoror ngOnChanges.

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

Responds to your server CORS Header

'Access-Control-Allow-Credentials' = true

This is the security provided CORS, you are not allowed to do this. You cannot use Access-Control-Allow-Origin= * if you want to allow credentials. You will need to specify the exact domain. try to specify

localhost:<portnumber>

See the following links for more information.

+1

:

ngAfterViewInit() {
   this.uploader.onAfterAddingFile = (item => {
      item.withCredentials = false;
   });
}
0

Source: https://habr.com/ru/post/1670059/


All Articles