HomeDocs
跳到主要内容

dlt.downloadFile

简介​

下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径 (本地路径)。

参数​

Object object

属性类型默认值必填说明最低版本
urlstring是请求的地址
saveNamestring否可为空,如果为空取的是 Url 最后分隔符后的字符串
headerstring否设置请求的 header,JSON string
timeoutnumber60000否超时时间,单位为毫秒。默认值为 60000。3.0.0 版本后支持
successfunction否接口调用成功的回调函数
failfunction否接口调用失败的回调函数
completefunction否接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数​

参数​

Object res​

属性类型说明
tempFilePathstring临时下载保存的路径
successstringtrue-成功

object.fail 回调函数​

参数​

Object res​

属性类型说明
errCodestring错误码
errMsgstring错误信息
successstringfalse-失败

errMsg 说明

错误信息说明
Download Fail,Data storage failed because of insufficient storage space: S001下载失败,存储空间不足
Download Fail,Exception_"+t.toString()+ ":D002下载失败:出现异常
Download Fail,appId is empty:D003下载失败:小程序 ID 不存在
Download Fail,downloadUrl is error:D004下载失败:下载地址有误
Download Fail,downloadPath is empty:D005下载失败:下载存储路径为空
Download Fail,onFailure_"+e.toString()+":D006下载失败
Download Fail,onResponse_" + e.toString() + ":D007下载失败

示例代码​

// pages/index/index.js

Page({
downloadFile() {
dlt.downloadFile({
url: "xxx",
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_private.mi@dlightek.com © 2024 MiniApp. All Rights Reserved.