angular - send image using http post to django restfull api -


filechange(event) {      debugger;      let filelist: filelist = event.target.files;      if (filelist.length > 0) {        let file: file = filelist[0];        let formdata: formdata = new formdata();          formdata.append('uploadfile', file, file.name);        let headers = new headers()        headers.append('authorization', this.token);        headers.append('content-type', 'application/json');        headers.append('content-disposition', 'form-data; filename="'+file.name+'"');                // content-disposition: form-data; name="fieldname"; filename="filename.jpg"          headers.append('content-type', 'multipart/form-data');        let options = new requestoptions({ headers: headers });        // let apiurl1 = "/api/uploadfileapi";          this.http.post('http://192.168.1.160:8000/profilepic/', {formdata:formdata}, options)          .map(res => res.json())          .catch(error => observable.throw(error))          .subscribe(          data => alert('success'),          error => alert(error)          )      }      // window.location.reload();      }
<input class="uploadfile-style" [(ngmodel)]="filepath" (change)="filechange($event)" name="ccontractorfpath"                                                                                                       size="10" type="file" enctype="multipart/form-data"> 

hii have write code post image in angular 2...but shows error unsupported media type \"application/json,multipart/form-data\" in request same file accepted when post postman

following 2 different curl commands

 1. accepted json          curl -x post \       http://192.168.1.223:8010/profilepic/ \       -h 'authorization: basic ywrtaw46ywrtaw4=' \       -h 'cache-control: no-cache' \       -h 'content-type: multipart/form-data; boundary=----webkitformboundary7ma4ywxktrzu0gw' \       -h 'postman-token: 794107c3-791d-e198-fe36-48f407a3ec8c' \       -f datafile=@/home/ashwini/pictures/b.jpeg    2. not accepted api         curl 'http://192.168.1.223:8010/profilepic/' -h 'authorization: 6df62b2d808c15acbdd8598d0153c8ca7e9ea28a' -h 'origin: http://localhost:4201' -h 'accept-encoding: gzip, deflate' -h 'accept-language: en-gb,en-us;q=0.8,en;q=0.6' -h 'user-agent: mozilla/5.0 (x11; linux x86_64) applewebkit/537.36 (khtml, gecko) chrome/59.0.3071.115 safari/537.36' -h 'content-type: application/json,multipart/form-data' -h 'accept: application/json, text/plain, */*' -h 'referer: http://localhost:4201/' -h 'connection: keep-alive' --data-binary $'{\n  "formdata": {}\n}' --compressed 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -