Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript数据丢失中以64为基数的任何文件_Javascript_Base64_Ionic2_Cordova Plugins - Fatal编程技术网

javascript数据丢失中以64为基数的任何文件

javascript数据丢失中以64为基数的任何文件,javascript,base64,ionic2,cordova-plugins,Javascript,Base64,Ionic2,Cordova Plugins,我正在尝试将媒体文件转换为Base64,以便用javascript上传到服务。我正在爱奥尼亚2中构建一个应用程序,并使用爱奥尼亚原生的MediaCapture插件捕捉图像。然后,将该图像转换为base64,如下所示: MediaCapture.captureImage(options) .then( (data: any) =>{ //MediaFile[] let imageLocalUrl = data[0].localURL; console.lo

我正在尝试将媒体文件转换为Base64,以便用javascript上传到服务。我正在爱奥尼亚2中构建一个应用程序,并使用爱奥尼亚原生的MediaCapture插件捕捉图像。然后,将该图像转换为base64,如下所示:

MediaCapture.captureImage(options)
  .then(
    (data: any) =>{ //MediaFile[]
      let imageLocalUrl = data[0].localURL;
      console.log("imageLocalUrl:"+imageLocalUrl);
      this.base64Lib.convertToBase64(imageLocalUrl).subscribe((iBase64Str)=>{
        this.imageBase64 = JSON.stringify(iBase64Str).split("base64,")[1].replace(/(^")|("$)/g, '');
        console.log("imageBase64:"+this.imageBase64);
      })
      // console.log(data)
    },
    (err: CaptureError) => console.error(err)
  );
基本64转换:

convertToBase64(path){
return Observable.create((observer)=>{
  let filePath = path;
  console.log("path in b64lib:"+path);
  (window as any).resolveLocalFileSystemURL(path,gotFile,failed);

  function gotFile(fileEntry){
    console.log("fileEntry:"+fileEntry);
    // observer.next(fileEntry);
    fileEntry.file(function(file){
      var fileReader = new FileReader();
      fileReader.onloadend = function(e){
        var content =  (e as any).target.result;
        // console.log("event:"+e);
        console.log("content:"+content);
        observer.next(content);
        // observer.complete();
      }

      fileReader.readAsDataURL(file);
    })
  }
当我尝试将控制台输出转换为图像时,我看到的是:

有人能帮我一下吗? 我使用localUrl,因为当我尝试通过完整路径使用文件时,它无法找到。我想只有持久性存储才能与fullpath配合使用


base64转换参考:

控制台输出
-您确定控制台输出已完成吗。大型控制台输出可能会被截断,因为没有人希望在调试过程中喷出大量数据tool@JaromandaX-你说得对。当我将base64作为image[src]时,它会显示完整的图像。非常感谢你。