How to load an image server in ionic 2/3

I am creating an application with Ionic 2. I need to take a photo from a gallery or camera and upload this picture to my server. I have this code that opens a 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

 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 is too long

+5
source share
1 answer

As you can see from the error description, it seems that you are trying to pass a value to one of the fields in the mysql table, which is less than the value you are trying to pass.

Try to output the options array and cross each of its values ​​against the corresponding db field, and if you find any discrepancy, change the corresponding field length accordingly.

Hope this helps!

0
source

Source: https://habr.com/ru/post/1275281/


All Articles