File Upload In Angular?

前端 未结 14 2541
执念已碎
执念已碎 2020-11-22 08:10

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

14条回答
  •  忘了有多久
    2020-11-22 08:56

    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));
    

提交回复
热议问题