5
votes

I'm building an app with Ionic 2. I need to take a photo from gallery or camera and upload this picture to my server. I have this code that opens the Gallery and takes a picture.

accessGallery() {
    this.camera.getPicture({
      sourceType: this.camera.PictureSourceType.SAVEDPHOTOALBUM,
      destinationType: this.camera.DestinationType.DATA_URL
    }).then((imageData) => {
      this.base64Image = 'data:image/jpeg;base64,' + imageData;
      this.uploadFile();
    }, (err) => {
      console.log(err); 
    });
  }

upload image to server side

uploadFile() {

      let body = new FormData();
      body.append('images', this.base64Image);
      let headers = new Headers({
        'token': this.token,
        'sid': this.sid,
        'user': this.user,
        'to': this.to,
        'node': this.node,
        'type':'image' 

      });
      let options = new RequestOptions({ headers: headers });
      console.log("header ----" +JSON.stringify(headers));
      console.log("images data body----" +JSON.stringify(body));

      this.http.post(this.apiurl,body,options)
          .map(res => res.json())
          .subscribe(
              data => {
                console.log(data);
              },
              err => {
                console.log("ERROR!: ", err);
              }
          );
    }

ERROR :- Field value too long

1
What is your backend? - David R
@David R node.js - Jayprakash Singh
What I meant to ask was, the node rest url to which you are trying post your image points to which database? - David R
@David R database myql - Jayprakash Singh

1 Answers

0
votes

As the error description clearly suggests, it seems you are trying to pass a value to one of your mysql table's field which is smaller than the value you are trying to pass.

Try outputting your options array and cross check each of its value against the respective db field and if you find any discrepancy modify the respective field length accordingly.

Hope this helps!