文件选取

[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.filePicker.open(success, error,options)

支持平台:

  • Android
  • iOS

参数说明

参数 类型 必填 说明
success Function 回调函数
error Function 回调函数
options Object 参数对象

success函数返回一个对象数组,数组里对象包含以下属性:

  • name(String) -- 文件名称
  • localURL(String) -- 文件本地URL(遵守cdvfile协议)
  • type(String) -- 文件mine type类型
  • lastModifiedDate(Number) -- 文件最后被修改的时间,毫秒
  • size(Number) -- 文件大小,单位 bytes
  • thumbLocalURL(String/选择文件时没有该参数) -- 缩略图本地URL(遵守cdvfile协议)
  • fullPath(String ) -- 文件的全路径(含file:///)

error函数返回一个字符串,错误信息

options 为参数对象,其属性可包含以下一项或多项:

  • image (bool / 必选) -- 图片选择,默认false
  • video (bool / 必选) -- 视频选择,默认false
  • audio (bool / 必选) -- 音频选择,默认false
  • document (bool / 必选) -- 文件选择,默认false

示例代码

// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
    // 监听’deviceready‘事件
    document.addEventListener('deviceready', onDeviceReady, false)
    function onDeviceReady(){
         navigator.filePicker.open(function (res) {
            alert(JSON.stringify(res))
        },function (err) {
            alert(JSON.stringify(err))
        },{image:true,video: false,audio: false,document: false})
    }
</script>

响应示例代码:

[
    {
        "fullPath": "file:///private/var/mobile/Containers/**_tmp.jpeg",
        "thumbLocalURL": "cdvfile://localhost/root/private/var/**_tmp_thumb.jpeg",
        "lastModifiedDate": 1578990108549.8376,
        "size": 201722,
        "localURL": "cdvfile://localhost/root/private/var/**_tmp.jpeg",
        "type": "image/jpeg",
        "name": "**_tmp.jpg"
    }
]

results matching ""

    No results matching ""