0

I want to pass document field in my form as an object like

formData.append('document', {
      uri: this.fileUrl,
      type: this.file.type,
      name: this.file.name
    });

There are multiple fields which I use like

const formData: any = new FormData();
    sellerType.map(x => {
      formData.append('sellerType', x);
    });
    formData.append('name', this.sellerRegisterForm.value.sellerName);
    formData.append('email', this.sellerRegisterForm.value.email);
    formData.append('password', this.sellerRegisterForm.value.password);
    formData.append('contactNo', this.sellerRegisterForm.value.contactNo);
    formData.append('comp_name', this.companyRegisterForm.value.companyName);
    formData.append('comp_contactNo', this.companyRegisterForm.value.contactNo);
    formData.append('document', {
      uri: this.fileUrl,
      type: this.file.type,
      name: this.file.name
    });

but it is not accepting !! Please anyone can help me with this or if I'm doing anything wrong then please corrent my code that how can I pass this kind of object in formdata...

radhika thakkar
  • 149
  • 2
  • 9

1 Answers1

0

You have to pass 3 separate fields via formData and need to prepare document object by reading those properties from formData at the API side.

formData.set("documentfileUrl", this.fileUrl);
formData.set("documenttype", this.file.type);
formData.set("documentname", this.file.name);

API side:

Document document = new Document();
document.fileUrl = formData.get("documentfileUrl");
document.type = formData.get("documenttype");
document.name = formData.get("documentname");