【问题标题】:Best way to send multiple images to server in IONIC 3在 IONIC 3 中将多个图像发送到服务器的最佳方式
【发布时间】:2020-05-02 15:16:09
【问题描述】:

使用离子框架文档中的实际示例,我的实现工作完美,但我现在的问题是遍历图像数组,以便我可以将选定的多个图像发送到服务器,我尝试了多种方法,对于-loop、do-while 和 normal

SelectCarImages(){
  this.options = {
              width: 600,
              height: 400,
              quality: 75,
              outputType: 1
            };
            this.imagePicker.getPictures(this.options).then((results) => {
              for (var i = 0; i < results.length; i++) {
                this.photos.push('data:image/jpeg;base64,' + results[i]);
                this.pictureData = results[i];
            //PictureData is the array of images
              }
            }, (err) => {
              (err);
            });  

            console.log('choose photo');
          }
        }


uploadMultipleImages(){
    var imageArr;
    for (var i = 0; i < this.pictureData.length; i++) {

      imageArr = this.pictureData[i]

    }
      let body = {
        name: "pix.jpg",
        foto_type: "Cars",
        file: imageArr
      };

      this.routes.postData("/fotos", body).subscribe(
        data => {
          let response = data as any;
          let ret = JSON.parse(response._body);

          if (ret) {
            console.log("pictures uploaded succesfully");
          } else {
            console.log(ret);
          }
        },
        error => {
          console.log(error);
        }
      );
  }

【问题讨论】:

    标签: arrays typescript ionic-framework ionic3 ionic4


    【解决方案1】:

    正如您所提到的,您喜欢以最合适的方式上传图片。不要使用 base64,因为它将是一个长字符串,并且会占用您移动设备的更多 CPU。您可以使用 File_URI 而不是在后端使用 PHP 中的 POST 或 FILES 从该 FILE_URI 创建图像。如果为这些图像文件创建对象数组。您可以在后端循环遍历它们,这将比 base64 优化得多。

    【讨论】:

    • 正如我所提到的,发送“多个”图像的适当方式,我什至进一步强调了它是什么,我想从客户端遍历图像数组。
    猜你喜欢
    • 2015-09-17
    • 2018-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    相关资源
    最近更新 更多