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

uniapp文件上传、下载

直接上代码

1、文件下载的

<view>
	<text   calss="download(index)">下载保存</text>
</view>
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、文件上传(安卓)

<tki-file-manager ref="filemanager" @result="resultPath"></tki-file-manager>
<view class="openFile">
		<button class="uploadBtn" type="primary" @click="openFile()">立即上传</button>
		<view ref="input" class="input"></view>
</view>

//引入组件
	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);
				}
			});
		},

}
可以交流!!!!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值