uniapp上传文件

用的是官方组件

					<view class="c-add-li">
						<text class="c-title">上传附件</text>
						
						<uni-file-picker 
						    v-model="infos.pathList" 
							file-mediatype="all"
							@select="select" 
							@progress="progress" 
							@success="success" 
							@fail="fail" 
							:auto-upload='false'
						>
						    <button>选择文件</button>
						</uni-file-picker>
					</view>
// 上传
			select(e){
				let that = this
				uni.showLoading({
					title: "图片上传中"
				});
				
				const tempFilePaths = e.tempFilePaths;
				for (var i in tempFilePaths) {//多文件
					uni.uploadFile({
						url: app.globalData.baseURL + 'api/mobile/attachment/upload', //上传接口
						header: {
							'X-Auth-Token': app.globalData.token
						},
					filePath: tempFilePaths[i],
					name: 'surface',
					success: (uploadFileRes) => {
						uni.hideLoading();
						const back = JSON.parse(uploadFileRes.data);
						if (uploadFileRes.statusCode == 200) {	
							that.infos.pathList.push(back.data);
						} else {
							uni.showToast(back.msg)
						}
					},
					fail: () => {
						uni.hideLoading();
						uni.showToast("图片上传失败,请联系开发!")
					},
					complete: function() {
						uni.hideLoading();
					}
				});
			}
			   
			},
			// 获取上传进度
			progress(e){
			    console.log('上传进度:',e)
			},
			
			// 上传成功
			success(e){
			    console.log('上传成功')
			},
			
			// 上传失败
			fail(e){
			    console.log('上传失败:',e)
			},

一个简易的复制到剪切板下载

		download(item){
				let that = this;
				uni.setClipboardData({
					data: app.globalData.baseURL + item.webPath,
					success: function() {
						uni.showModal({
						content: '下载链接已保存到粘贴板,请打开浏览器后粘贴到地址栏下载文件',
						showCancel: false,
					fail() {
						uni.showToast({
							title: '复制失败',
							duration: 2000,
							icon: 'none'
							});
						}
					})
				}
			});
			},
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值