0

I have successfully made the post request but in the request body the formData is empty. i don't know what might be the cause

  trigger() {
    let element = document.getElementById('upload_file') as HTMLInputElement;
    element.click();
  }


  onChange(file: any) {
    this.FILE = file.files[0];
    this.fileName = file.files[0].name;
  }

 uploadDocument() {
  this.document = new Document();
  this.document.value= this.VALUE;
  .
  .
  .
  this.document.value= this.VALUE;

  let document = JSON.stringify(this.document);
  const formData: FormData = new FormData();
  formData.append('file', this.FILE, this.FILE.name);

      return this.http.post(this.baseURL + '/rest/document/', {document, formData}).subscribe((data: any) => {
      this.connection.creating = false;
    })
  }

1 Answers1

0

set your document field as a part of FormData

  let document = JSON.stringify(this.document);
  const formData: FormData = new FormData();
  formData.append('file', this.FILE, this.FILE.name);
  formData.append('document', document);

  return this.http.post(this.baseURL + '/rest/document/', formData).subscribe((data: any) => {
      this.connection.creating = false;
    })
  }
icekson
  • 363
  • 1
  • 3