[Solved] How to send Zip file in angular


Solved

Thanks for all down votes with no solution providing! here is how i solved my issue hope it help those in need:

View

<ion-input type="file" formControlName="zipFiles" (change)="zipFilesUpload($event)" placeholder="Zip Files"></ion-input>

Controller

zipFiles: File = null;

zipFilesUpload(event) {
  this.zipFiles = <File>event.target.files[0];
}

approveDistributor() {
    const distributorForm2 = this.distributorForm.value;

    const fd = new FormData();
    fd.append('files', this.zipFiles, this.zipFiles.name);

    // tslint:disable-next-line: max-line-length
    this.verifyService.distributorForm(fd).subscribe(
      data => {
        this.alertService.presentToast('Sent successfully.');
      },
      error => {
        this.alertService.presentToast('The given data was invalid.');
      },
      () => {

        //
      }
    );
}

Service

distributorForm(fd) {
  const headers = new HttpHeaders({
    Authorization : this.token.token_type + ' ' + this.token.access_token
  });

  return this.http.post(this.env.companyDocs, fd, { headers });
}

Now I can send binary data to backend and store data in both database and file storage.

1

solved How to send Zip file in angular