我正在使用 Ionic 2 构建一个应用程序。我需要从画廊或相机拍摄一张照片并将这张照片上传到我的服务器。 我有打开图库并拍照的代码。
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);
});
}
上传图片到服务器端
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);
}
);
}
错误:- 字段值太长
最佳答案
正如错误描述清楚地表明的那样,您似乎正在尝试将一个值传递给您的 mysql 表的字段之一,该值小于您尝试传递的值。
尝试输出您的 options
数组并对照相应的数据库字段交叉检查它的每个值,如果您发现任何差异,相应地修改相应的字段长度。
希望对您有所帮助!
关于ios - 如何在 ionic 2/3 中上传图像服务器端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48717574/