Skip to content

远程下载文件到本地

方法名

downloadFile

用法

用法示例

js
module.downloadFile({
  url: "http://www.yeyuboke.com/svga/1.svga",
  saveDir: "/storage/emulated/0/leven_file/"
}, res => {
  console.log(res)
})

参数说明

参数名参数类型是否必填默认值参数描述
urlStringurl地址
saveDirString保存的文件地址(绝对路径)

回调

回调示例

json
{
    "data": {
        "type": "start"
    },
    "message": "开始下载",
    "code": 0
}

{
    "data": {
        "percent": 0.15394142772234098,
        "type": "downloading",
        "size": 250197,
        "totalSize": 1625274
    },
    "message": "下载中",
    "code": 0
}

{
    "data": {
        "type": "success",
        "path": "/storage/emulated/0/leven_file/1.svga"
    },
    "message": "下载完成",
    "code": 0
}

回调说明

参数名参数类型参数描述
messageString消息提示
dataObject数据对象
data.typeString下载类型,start:开始下载,downloading:下载中,success:下载完成,error:下载出错
data.percentFloat当前下载的进度(<=1)
data.sizeInteger已下载的大小,单位:字节
data.totalSizeInteger文件总大小,单位:字节
data.pathString下载完成后的文件路径
codeInteger返回类型,0.成功,其他:失败