How to import file in Angular

Use in HTML file.

<input type="file" (change)="upload($event.target.files)" />

Use in TS file

upload(files: File[]) 
{
  this.basicUpload(files);
}

basicUpload(file:File) 
{
   var formData = new FormData();
   formData.append('file', files);
   this.http.post('ApiURL', formData).subscribe((event) => {
       console.log('done');
    });
}

Note: don't use heder "Content-Type": "application/json"

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments