下载文件(http.download)
函数
下载是否成功 = http.download(地址, 保存路径 ,[超时时间], [回调函数])
参数
-
地址 文本型
这个函数不会对地址进行 URL 编码, 需自行编码
-
保存路径 文本型
-
超时时间 整数型
可选 默认 60秒
-
回调函数 函数型
可选 ,以下是回调函数 参数
-
文件总大小 整数型
-
已下载大小 整数型
-
当前下载速度 整数型
-
返回值
- 状态 布尔型
说明
使用HTTP 协议 下载文件
示例
--下载一个视频文件 然后保存到相册
local savePath = "/var/mobile/Media/svip/res/55.mp4"
local status = http.download("http://tk.taobao6.vip/EC/video/5.mp4", savePath ,10 , function (totalLength, currentLength, downloadSpeed)
print(string.format("文件总大小为:%.2f.mb 当前已完成下载:%.2f.mb 当前下载速度: %.2f.mb" , totalLength / 1024 / 1024 ,currentLength / 1024 / 1024 , downloadSpeed / 1024 / 1024))
end)
if status then
local s ,e = mobile.saveVideoFileToAlbum(savePath)
print(s and "保存到相册成功" or "保存到相册失败 error:= " ..e)
end