ios - 如何在 ionic 2/3 中上传图像服务器端

标签 ios node.js ionic-framework server ionic2

我正在使用 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/

相关文章:

ios - 添加自定义build设置时,xcodebuild 存档生成格式错误的 xcarchive

iOS - 使 UIImageView 调整大小以适应 UILabel 和 AutoLayout

javascript - 从字符串中提取信息

javascript - 使用bulkDelete时出现 promise 拒绝错误

javascript - 如何将表单数据发布到 Ionic 中的应用内浏览器?

android - android中的 ionic 通知

ios - 翠鸟框架不下载图像

ios - 在更改 VC 之前获取并存储 PanoramaView 的位置

node.js - 永远记录和 logrotate

angular - 无法绑定(bind)到 'formGroup',因为它不是 'form' 的已知属性。 ionic v5.2.2 中的错误