uniapp非图片文件上传文件下载非图片

uniapp文件上传、下载

直接上代码

1、文件下载的


	下载保存

download(index) {
			var _this = this
			uni.downloadFile({
				url: _this.list[index].fileUrl, //仅为示例,并非真实的资源
				success: (res) => {
					var path = res.tempFilePath
					console.log(path);
					if (res.statusCode === 200) {
						// preview
						uni.openDocument({
							filePath: path,
							success: function(res) {
								console.log('打开文档成功');
								console.log(res);
							}
						});
						//文件保存
						uni.saveFile({
							tempFilePath: path,
							success: function(res) {
								var savedFilePath = res.savedFilePath;
								console.log(savedFilePath)
								uni.showToast({
									title: '下载成功',
									content: savedFilePath,
									duration: 500
								});
								uni.getSavedFileList({
									success: function(res) {
										console.log(res.fileList);
									}
								});
							}
						});
					}
				}
			});
		},

2、文件上传(安卓)



		
		


//引入组件
	import tkiFileManager from "@/components/tki-file-manager.vue"  
	methods: {
	    //打开手机文件
		openFile() {
			var _this = this
			_this.$refs.filemanager._openFile()
		},
		resultPath(e) {
			let _this = this
			_this.path = e
			const uploadTask = uni.uploadFile({
				//url:  'http://192.168.0.188:8080/f/craftsman/article/uploadArticleFile', //仅为示例,
				filePath: "file:/" + _this.path,
				name: 'file',
				formData: { //参数可以根据真实接口写
					'articleId': _this.articleId + '',
					'fileTitle	': '123',
					'fileSubtitle': '123',
					'fileType': '3'
				},
				success: function(res) {
					console.log(res.data.success);
					console.log(_this.path)
					var data = JSON.parse(res.data);
				}
			});
		},

}
可以交流!!!!

你可能感兴趣的:(uniapp)