I'm trying to upload some files to an Express server, the server is using the cors() module like this
app.use(cors());
this is the Angular 2 code to upload the files
let formData:FormData = new FormData();
for(let i = 0; i < files.length; i++) {
let file = files[i];
formData.append(`file`+(i+1), file, file.name);
}
let token = localStorage.getItem('supersecrettoken');
let headers = new Headers();
headers.append("Content-Type", 'multipart/form-data');
headers.append("auth", token);
return this.http.post(`${Constants.SERVER_IP}/imports`, formData, {headers: headers})
.map(response => {
return response.json();
})
.catch(this.logger.handleError).share();
Now this returns the following error
No 'Access-Control-Allow-Origin' header is present on the requested resource
If I change the multipart/form-data to application/json it will work.
How can I upload multiple files to the server then?
Regards!