离子copyFile错误代码5,ENCODING_ERR

时间:2018-07-30 07:51:16

标签: angular cordova ionic-framework plugins

我想知道是什么问题。 this.file-是导入的离子本机File插件。

import { File } from '@ionic-native/file';

  constructor(
    ...
    private file: File,
    ...) {
    super();
  }

我的代码:

  // Copy the image to to the application storage directory
  private copyFileToLocalDir(imagePath, newFileName) {
    // Special handling for Android library
    const imageDir = imagePath.substr(imagePath.lastIndexOf('/') + 1);
    const fileName = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);

    console.log('imagePath:');
    console.log(imagePath);
    console.log('imageDir:');
    console.log(imageDir);
    console.log('fileName:');
    console.log(fileName);
    console.log('this.file.dataDirectory:');
    console.log(this.file.dataDirectory);
    console.log('newFileName:');
    console.log(newFileName);

    this.file
      .copyFile(imageDir, fileName, this.file.dataDirectory, newFileName)
      .then(
        () => {
          this.uploadImage(newFileName);
        },
        (err) => {
          console.log('File save error:');
          console.log(err);
          this.notificationService.errorMessage('Ошибка сохранения файла');
        }
      );
  }

赔率:

imagePath:
file:///storage/emulated/0/Android/data/io.ionic.starter/cache/1532935809457.jpg
imageDir:
1532935809457.jpg
fileName:
file:///storage/emulated/0/Android/data/io.ionic.starter/cache/
this.file.dataDirectory:
file:///data/user/0/io.ionic.starter/files/
newFileName:
1532935810087.jpg
File save error:
FileError
code: 5
message: "ENCODING_ERR"

代码在我的大型重构之前和离子CLI更新之前都可以运行。我以前使用的是Ionic v3.2.0,现在是v4.0.1

出什么问题了?

1 个答案:

答案 0 :(得分:-1)

我发现了问题。 这样说,没人在这里看到它。

imageDir:
1532935809457.jpg
fileName:
file:///storage/emulated/0/Android/data/io.ionic.starter/cache/

重构代码时,我无意间切换了变量名。