【问题标题】:decode the filename of a DirectoryEntry returned by window.resolveLocalFileSystemURL with content://使用 content:// 解码 window.resolveLocalFileSystemURL 返回的 DirectoryEntry 的文件名
【发布时间】:2026-01-12 14:20:04
【问题描述】:

我正在尝试使用 window.resolveLocalFileSystemURL 函数检索 Google Drive 提供的 content:// URI 的本地路径。

这是传入的意图对象:

{
  "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"
}

这是DirectoryEntry,如the documentation of cordova-plugin-file 中所述,我可以检索 blob 和基础文件:

{
  "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
}

我确定文件名是用enc=fhNPFErrgrEv9o4Q0EfWItmhwQRdSI8diNatIJQGsbDn8UOC 编码的,但我无法解码。


由 Dropbox 中的意图创建的完全相同的对象:

意图对象:

{
  "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}"
}

directoryEntry 对象:

{
  "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"
}

blob/文件对象:

{
  "name": "IMG_20180116_124017_dropbox.jpg",
  "localURL": "cdvfile://localhost/sdcard/Android/data/com.dropbox.android/files/u702227782/scratch/IMG_20180116_124017_dropbox.jpg",
  "type": "image/jpeg",
  "lastModified": 1524043057000,
  "lastModifiedDate": 1524043057000,
  "size": 1597052,
  "start": 0,
  "end": 1597052
}

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      最近更新 更多