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"

Leave a Reply

Your email address will not be published. Required fields are marked *