1

I'm trying to upload files in my angular2 application. Currently I'm using the ng2-file-upload directives and it works for uploading files. However, I would like to also upload a JSON object.Please help me

  • What do you mean by upload a JSON object ? Send it by an http request ? – Radouane ROUFID Jul 20 '17 at 06:02
  • shopcontact(request) {debugger; var front_print=this.requestv; var back_print=this.requestv; let front_printvalue: File = this.requestv[0]; let back_printvalue: File = this.requestv[0]; var formData = new FormData(); formData.append("front_print",front_printvalue,front_printvalue.name); formData.append('back_print',back_printvalue,back_printvalue.name); return this._http.post(this._url + 'shop', request, { headers: headers, – vasudevarao Jul 20 '17 at 06:19
  • i want to file upload along with json data – vasudevarao Jul 20 '17 at 06:19
  • var tshirtbody = "event_name=" + request.eventname + "&name=" + "vasu"+ "&front_print=" + fdg+ "vasu" + "&item_quality=" + 2 + "&email=" + request.email + "&mobile=" + request.mobile + "&no_of_items=" + request.nooftshirts + "&item_type=" + request.tshirttype + "&text_print=" + request.text_print; var formData = new FormData(); formData.append("front_print",front_printvalue,front_printvalue.name); formData.append('back_print',back_printvalue,back_printvalue.name); return this._http.post(this._url + 'shop', body,formData ) – vasudevarao Jul 20 '17 at 06:27
  • I finally found a proper way to upload a file and send some JSON within the same request and made a proper answer here: https://stackoverflow.com/questions/39693966/how-to-angular2-post-json-data-and-files-in-same-request/47408232#47408232 – maxime1992 Nov 21 '17 at 08:19

0 Answers0