file:// 与 cdvfile://文件URI路径转换

[!TIP|labelVisibility:hidden|iconVisibility:hidden] resolveLocalFileSystemURL(fileURL,success,error)

支持平台:

  • Android
  • iOS

参数说明

参数 类型 必填 说明
fileURL String 需要转换的文件路径,文件开头是file://或者cdvfile://
success Function 路径转换的回调函数
error Function 路径转换的回调函数

示例代码

cdvfile://转file://

// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
    // 监听’deviceready‘事件
    document.addEventListener('deviceready', onDeviceReady, false)
    function onDeviceReady(){
    //cdvfile://转file://
    resolveLocalFileSystemURL('cdvfile://localhost/cache/com.supconit.hcmobile.ios/tmp/IMG_0727.jpeg', function(entry) {
    alert(JSON.stringify(entry.toURL()));
    //var nativePath = entry.toURL();
    //alert('Native URI: ' + nativePath);
    //document.getElementById('img').src = nativePath;
    },function(error){
    alert('文件不存在');
    })
  }
</script>

响应成功示例代码:

"file:///var/mobile/Containers/Data/Application/95DF3BE1-41FE-4D40-9F39-BB6B1E7678DB/Library/Caches/com.supconit.hcmobile.ios/tmp/IMG_0727.jpeg"

file://转cdvfile://

// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
    // 监听’deviceready‘事件
    document.addEventListener('deviceready', onDeviceReady, false)
    function onDeviceReady(){
    //file://转cdvfile://
   resolveLocalFileSystemURL('file:///var/mobile/Containers/Data/Application/95DF3BE1-41FE-4D40-9F39-BB6B1E7678DB/Library/Caches/com.supconit.hcmobile.ios/tmp/IMG_0737.jpeg',function(entry) {
   alert(JSON.stringify(entry.toInternalURL()));
   //alert('cdvfile URI: '+entry.toInternalURL());
   //document.getElementById('img').src=entry.toInternalURL();
  },function(error){
    alert('文件不存在');
  })
  }
</script>

响应成功示例代码:

"cdvfile://localhost/cache/com.supconit.hcmobile.ios/tmp/IMG_0737.jpeg"

results matching ""

    No results matching ""