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

5
  • What do you mean by upload a JSON object ? Send it by an http request ? Commented Jul 20, 2017 at 6: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, Commented Jul 20, 2017 at 6:19
  • i want to file upload along with json data Commented Jul 20, 2017 at 6: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 ) Commented Jul 20, 2017 at 6: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: stackoverflow.com/questions/39693966/… Commented Nov 21, 2017 at 8:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.