解码window.resolveLocalFileSystemURL返回的DirectoryEntry的文件名,内容为://

时间:2018-04-18 10:22:56

标签: android cordova cordova-plugins cordova-plugin-file

我正在尝试使用host = view.settings().get('remote_subl.host', None) 功能检索Google云端硬盘提供的content:// URI的本地路径。

这是传入的意图对象:

window.resolveLocalFileSystemURL

{ "action": "android.intent.action.SEND", "extras": { "android.intent.extra.STREAM": "content://com.google.android.apps.docs.storage.legacy/enc%3DfhNPFErrgrEv9o4Q0EfWItmhwQRdSI8diNatIJQGsbDn8UOC%0A" }, "clipItems": [ { "uri": "content://com.google.android.apps.docs.storage.legacy/enc%3DfhNPFErrgrEv9o4Q0EfWItmhwQRdSI8diNatIJQGsbDn8UOC%0A", "type": "image/jpeg", "extension": "jpg" } ], "type": "image/jpeg", "flags": 453509121, "component": "ComponentInfo{io.cozy.drive.mobile/io.cozy.drive.mobile.MainActivity}" } 返回

window.resolveLocalFileSystemUrl

这是{ "isFile": true, "isDirectory": false, "name": "enc=fhNPFErrgrEv9o4Q0EfWItmhwQRdSI8diNatIJQGsbDn8UOC\n", "fullPath": "/com.google.android.apps.docs.storage.legacy/enc=fhNPFErrgrEv9o4Q0EfWItmhwQRdSI8diNatIJQGsbDn8UOC\n", "filesystem": "<FileSystem: content>", "nativeURL": "content://com.google.android.apps.docs.storage.legacy/enc%3DfhNPFErrgrEv9o4Q0EfWItmhwQRdSI8diNatIJQGsbDn8UOC%0A" } ,如the documentation of cordova-plugin-file中所述,我可以检索blob和基础文件:

DirectoryEntry

我确信文件名是在{ "name": "content", "localURL": "cdvfile://localhost/content/com.google.android.apps.docs.storage.legacy/enc%3DfhNPFErrgrEv9o4Q0EfWItmhwQRdSI8diNatIJQGsbDn8UOC%0A", "type": "image/jpeg", "lastModified": 1524043045078, "lastModifiedDate": 1524043045078, "size": 1597052, "start": 0, "end": 1597052 } 中编码的,但我无法解码它。

来自dropbox的意图创建的完全相同的对象:

意图对象:

enc=fhNPFErrgrEv9o4Q0EfWItmhwQRdSI8diNatIJQGsbDn8UOC

directoryEntry对象:

{
  "action": "android.intent.action.SEND",
  "extras": {
    "android.intent.extra.STREAM": "file:///storage/emulated/0/Android/data/com.dropbox.android/files/u702227782/scratch/IMG_20180116_124017_dropbox.jpg"
  },
  "clipItems": [
    {
      "uri": "file:///storage/emulated/0/Android/data/com.dropbox.android/files/u702227782/scratch/IMG_20180116_124017_dropbox.jpg"
    }
  ],
  "type": "image/jpeg",
  "flags": 272629763,
  "component": "ComponentInfo{io.cozy.drive.mobile/io.cozy.drive.mobile.MainActivity}"
}

blob / file对象:

{
  "isFile": true,
  "isDirectory": false,
  "name": "IMG_20180116_124017_dropbox.jpg",
  "fullPath": "/Android/data/com.dropbox.android/files/u702227782/scratch/IMG_20180116_124017_dropbox.jpg",
  "filesystem": "<FileSystem: sdcard>",
  "nativeURL": "file:///storage/emulated/0/Android/data/com.dropbox.android/files/u702227782/scratch/IMG_20180116_124017_dropbox.jpg"
}

1 个答案:

答案 0 :(得分:0)

我将cordova-plugin-filepath更新为v1.3.0,它就像魅力一样!