Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
POST a form in which some element are file

In a js web project, I want to POST a form with a complexe json schema, and in which some field will be file.

How do I do It?

I currently upload a file alone like this

  const data = new FormData();
    data.append('mimetype', file.type);
    data.append('filename', file.name);
    data.append('file', file);
    return this.httpClient.post(url, data)

but I want my new form look like this:

 var data ={username:"John doe", 
    profilPhoto:{mimetype:..., filename:..., file: ...},
    house:{
       photo:{mimetype:..., filename:..., file: ...},
    },
    documents:[{mimetype:..., filename:..., file: ...}]

  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As suggested in the comments encode your file to base64 then decode on the backend and save it as a blob. Another option would be to use FormData as you do. For the array of objects, you can use JSON.stringify and then JSON.parse on backend.

  addFile(data:any): Observable<any> {
    const postData=new FormData();
    postData.append('username', data.username);
    postData.append('profilPhoto', data.profilePhotoFile);
    postData.append('house', data.houseFiles);
    postData.append('documents', JSON.stringify(data.documents);
    let API_URL = this.endpoint+`/add-file`;
    return this.http.post(API_URL, postData)
  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!