Невозможно указать путь загрузки изображения - ionic 3 - PullRequest
0 голосов
/ 05 сентября 2018

Я пытаюсь загрузить изображение с помощью ионного приложения на php-сервер после обрезки с помощью средства выбора изображений. Изображение не существует в указанном пути.

Можно ли указать путь для сохранения обрезанного изображения?

Это мой код:

getImage()
{
  var options = {
   maximumImagesCount: 1,
   width: 800,
   height: 800,
   quality: 80,
  };

 this.imagePicker.getPictures(options)
 .then((results) => {
   this.reduceImages(results).then(() => {
        this.photos = results;

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

            let d = new Date();
            let time = d.getTime();
            let options_f: FileUploadOptions = {
              fileKey: 'file',
              fileName: this.name + time + '.jpg',
              chunkedMode: false,
              mimeType: "image/jpg",
            };

            let url='https://elevather.com/mentor/file_upload.php';

            fileTransfer.upload(this.photos, url, options_f)
            .then((data) => {
              if(data["_body"]=="yes")
                this.msg = 'yes';
              else
                this.msg = 'no';
            }, (err) => {
              console.log('upload failed!');
            });

    }, (err) => { });
  }, (err) => { });
}

reduceImages(selected_pictures: any) : any{
  return selected_pictures.reduce((promise:any, item:any) => {
    return promise.then((result) => {
      return this.cropService.crop(item, {quality: 80})
       .then(cropped_image => console.log('Done'));
     });
  }, Promise.resolve());
}

Есть ли другой способ сделать это?

Ответы [ 2 ]

0 голосов
/ 06 сентября 2018

Заменяли ли вы this.photos на croppedImage? Смотрите код ниже.

getImage()
{
  var options = {
   maximumImagesCount: 1,
   width: 800,
   height: 800,
   quality: 80,
  };

 this.imagePicker.getPictures(options)
 .then((results) => {
   this.reduceImages(results).then((croppedImage) => {
        this.photos = croppedImage;

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

            let d = new Date();
            let time = d.getTime();
            let options_f: FileUploadOptions = {
              fileKey: 'file',
              fileName: this.name + time + '.jpg',
              chunkedMode: false,
              mimeType: "image/jpg",
            };

            let url='https://elevather.com/mentor/file_upload.php';

            fileTransfer.upload(this.photos, url, options_f)
            .then((data) => {
              if(data["_body"]=="yes")
                this.msg = 'yes';
              else
                this.msg = 'no';
            }, (err) => {
              console.log('upload failed!');
            });

    }, (err) => { });
  }, (err) => { });
}

reduceImages(selected_pictures: any) : any{
  return selected_pictures.reduce((promise:any, item:any) => {
    return promise.then((result) => {
      return this.cropService.crop(item, {quality: 80})
       .then(cropped_image => cropped_image);
     });
  }, Promise.resolve());
}
0 голосов
/ 05 сентября 2018

вы пытались получить доступ к этому пути? это то место, где оно сохраняется (https://github.com/jeduan/cordova-plugin-crop/blob/master/src/android/CropPlugin.java).

 private String getTempDirectoryPath() {
    File cache = null;

    // SD Card Mounted
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
                "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/");
    }
    // Use internal storage
    else {
        cache = cordova.getActivity().getCacheDir();
    }

    // Create the cache directory if it doesn't exist
    cache.mkdirs();
    return cache.getAbsolutePath();
}
...