【问题标题】:Ionic5 IOSFilePicker convert uri to blob buffer is emptyIonic 5 IOS FilePicker 将 uri 转换为 blob 缓冲区为空
【发布时间】:2022-08-20 04:46:08
【问题描述】:

我想将pdf、word、excel和ppt uri转换为blob,我使用cordova-plugin-file中的 this.file.resolveLocalFilesystemUrlthis.file.readAsArrayBuffer并获得空缓冲区。所以我的 Blob 也是空的。

这是我的代码

getFiles(){
  console.log(\'GetFiles \');

  this.filePicker.pickFile().then(uri => {

     console.log(\' getFiles uri \'+JSON.stringify(uri));




    this.makeFileIntoBlob(uri).then((resolve)=>{
       console.log(\' makeFileIntoBlob resolve \'+JSON.stringify(resolve));
    }).catch(err=>console.log(\' makeFileIntoBlob Error\', JSON.stringify(err))); 


 }).catch(err => console.log(\'Error\', err)); 
} 

// FILE STUFF
makeFileIntoBlob(_Path) {
// INSTALL PLUGIN - cordova plugin add cordova-plugin-file
return new Promise((resolve, reject) => {
  console.log(\'path \'+_Path);
  let fileName = \"\";
  this.file.resolveLocalFilesystemUrl(\'file:///\'+_Path).then(fileEntry => {
      console.log(\'fileEntry \'+JSON.stringify(fileEntry));
      let { name, nativeURL } = fileEntry;

      // get the path..
      let path = nativeURL.substring(0, nativeURL.lastIndexOf(\"/\"));
      console.log(\' file path \'+path);
      fileName = name;
      console.log(\'file Name \'+fileName);
      // we are provided the name, so now read the file into a buffer
      return this.file.readAsArrayBuffer(path, name);
    }).then(buffer => {
     
      console.log(\'buffer \'+JSON.stringify(buffer));
      // get the buffer and make a blob to be saved
      let fileBlob = new Blob([buffer], { type: \"application/pdf\" });
      console.log(\'fileBlob \'+JSON.stringify(fileBlob));
      // pass back blob and the name of the file for saving
      // into fire base
      resolve({
        fileName,
        fileBlob
      });
    }).catch(e => console.log(\'resolveLocalFilesystemUrl e \'+JSON.stringify(e)));
  
});

}

URI: \"/private/var/mobile/Containers/Data/Application/099A9287-B088-4A92-A052-33CB3577B8F0/tmp/com.focus.messenger-Inbox/ASM9_M02_L02_EN___6a0aa8c4-8cb2-4ba2-b283-f623848d94e0.pdf\"

本机网址:file:///var/mobile/Containers/Data/Application/099A9287-B088-4A92-A052-33CB3577B8F0/tmp/com.focus.messenger-Inbox/ASM9_M02_L02_EN___6a0aa8c4-8cb2-4ba2-b283-f623848d94e0.pdf

路径:file:///var/mobile/Containers/Data/Application/099A9287-B088-4A92-A052-33CB3577B8F0/tmp/com.focus.messenger-Inbox

文件名:file Name ASM9_M02_L02_EN___6a0aa8c4-8cb2-4ba2-b283-f623848d94e0.pdf

缓冲 {}

文件块 {}

    标签: angular blob buffer ionic5 cordova-plugin-file


    【解决方案1】:

    你有没有为这个很好的答案。 (没有足够的代表发表正常评论)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-07
      • 2020-08-27
      • 2021-01-14
      • 2019-10-06
      • 2022-08-05
      • 2020-04-26
      • 2018-03-26
      • 2015-08-13
      相关资源
      最近更新 更多