uni-app:使用uni.downloadFile下载文件并保存到手机

编程知识 更新时间:2023-05-02 19:50:28

在uni-app中下载文件需要先获取文件的临时路径,然后再进行保存,才算下载成功:

// #ifdef APP-PLUS
				const downloadTask = uni.downloadFile({
						url: 'http://xxxxxxxx/'+url, //仅为示例,并非真实的资源
							success: (res) => {
								if (res.statusCode === 200) {
									console.log('下载成功');
								}
								let that = this;
								uni.saveFile({
									tempFilePath: res.tempFilePath,
										success: function(red) {
											uni.openDocument({
												filePath:red.savedFilePath,
												success: (sus) => {
													console.log('成功打开')
												}
											})
											console.log(red)
										}
									});
								}
							})
							downloadTask.onProgressUpdate((res) => {
								console.log('下载进度' + res.progress);
								console.log('已经下载的数据长度' + res.totalBytesWritten);
								console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
						})
				//#endif

更多推荐

uni-app:使用uni.downloadFile下载文件并保存到手机

本文发布于:2023-04-28 09:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/4ead1f6b733fbe3d83d06b95701ca63e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并保存   文件   手机   uni   app

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 108324文章数
  • 27384阅读数
  • 0评论数