I know this is very a general question but I am failing to upload a file in Angular 2. I have tried
1) http://valor-software.com/ng2-file-upload/ and
2) h
This is useful tutorial, how to upload file using the ng2-file-upload and WITHOUT ng2-file-upload.
For me it helps a lot.
At the moment, tutorial contains a couple of mistakes:
1- Client should have same upload url as a server,
so in app.component.ts
change line
const URL = 'http://localhost:8000/api/upload';
to
const URL = 'http://localhost:3000';
2- Server send response as 'text/html', so in app.component.ts
change
.post(URL, formData).map((res:Response) => res.json()).subscribe(
//map the success function and alert the response
(success) => {
alert(success._body);
},
(error) => alert(error))
to
.post(URL, formData)
.subscribe((success) => alert('success'), (error) => alert(error));