How to send image on http.post

I use this code blocks , but gives me error : 404; I tried api on postman , api success
what is my wrong?

changeprofileimg()
  {
    this.camera.getPicture({
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
      destinationType: this.camera.DestinationType.DATA_URL,
      quality: 100,
      encodingType: this.camera.EncodingType.PNG,
      targetHeight:500,
      targetWidth:500,
      correctOrientation:true
    }).then(imageData => {

      const image = 'data:image/jpeg;base64,'+imageData;   
      var veri;   
      var headers = new Headers();
      headers.append('Accept', 'application/json');
      headers.append('Authorization' , 'Bearer '+this.globalvars.getToken());
      headers.append('Content-Type', 'multipart/form-data');
      let options = new RequestOptions({ headers: headers });
      

      let postParams = {
        file:image
      }
      
      this.http.post("http://.../api/profile/image/upload", postParams, options)
        .subscribe(data => {
          console.log( data['_body']);
          veri=data['_body'];
          veri = veri.replace(/\\/g, "");
          veri = JSON.parse(veri);
          console.log(veri);
        });

    });
  }
1 Like

can anybody help me please?

did you find a way to do this? I’ve been searching for some days but still nothing …:frowning:

Are you in charge of the end point? If so can you send your image as base64 and reconstruct on the server?

our back-end team says it not a good idea to send base64 images, and they are right. as it puts heavy process on both client and server. so right now im following this tutorial hoping it would finally work. looks like i should copy the captured file on the phone and get a current path and then send it to http post via file transfer plugin… many plugins to add for one goal… but lookslike the only way…
i’ll report my experience after

Okay - I do the base64 thing - have with about a dozen systems. It’s quite expensive with something like videos, not a great idea - but images, even 7-8mb ones - never had an issue.

1 Like

You can flow the Link
Good Luck
Thank you.