【问题标题】:send multiple images via file transfer plugin ionic 3通过文件传输插件 ionic 3 发送多个图像
【发布时间】:2020-01-15 10:24:42
【问题描述】:

我正在开发应用程序,我需要发送多张图片,

我想知道是否有任何方法可以通过文件传输插件发送多个图像,

这是我的代码:

  const options: CameraOptions = {
    quality: 100,
    destinationType: this.camera.DestinationType.FILE_URI,
    sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
  }

  this.camera.getPicture(options).then((imageData2) => {
    this.imageURI2 = imageData2;
  }, (err) => {
    console.log(err);
  });

上传

  const fileTransfer: FileTransferObject = this.transfer.create();

    let options: FileUploadOptions = {
      fileKey: 'file',
        fileName: 'name.jpg',
        headers: {
          Connection: "close"
        }
    }
      options.chunkedMode = false;

      if(this.imageURI1 != null){
        fileTransfer.upload(this.imageURI1, 
   'https://test.test.com/uplaodphoto.php', options)
        .then((data) => {
          alert("success");
          this.imageFileName1 = 
   "https://test.test.com/images/name.jpg"

        }, (err) => {
          alert("error"+JSON.stringify(err));
        });

【问题讨论】:

    标签: ionic-framework ionic3


    【解决方案1】:

    用户图像选择器插件Cordova Image Picker

    用法:

        import { ImagePicker } from '@ionic-native/image-picker';
    
    
        constructor(private imagePicker: ImagePicker) { }
    
    export class YourPage {
       pickImages(){
         this.imagePicker.getPictures(options).then((results) => {
           for (var i = 0; i < results.length; i++) {
              console.log('Image URI: ' + results[i]);
              this.imageUpload(results[i])
          }
        }, (err) => { });
    }
    
        // Upload Image function. 
    
        imageUpload(path) {
          const fileTransfer: FileTransferObject = this.transfer.create();
          let options: FileUploadOptions = {
              fileKey: 'image',
              fileName: '.png',
              chunkedMode: false,
              //mimeType: "image/jpeg",
            }
    
            fileTransfer.upload(path, 'https://api.com/image-upload', options)
              .then((data) => {
              console.log(data+" Uploaded Successfully");
              let res = JSON.parse(data.response);
              if (res.success == true) {
    
              }
              this.loader.dismiss();
    
            }, (err) => {
              console.log(err);
    
            });
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-16
      • 2019-07-20
      • 2019-07-03
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      • 2020-01-10
      • 1970-01-01
      • 2011-01-09
      相关资源
      最近更新 更多