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

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

// #ifdef APP-PLUS
				const downloadTask = uni.downloadFile({
						url: 'http://xxxxxxxx.com.cn/'+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

你可能感兴趣的:(Vue,websocket,物联网,es6)