uniapp上传图片视频

uploadFile() {
				uni.showToast({
					title: '请上传正脸照片或请上传含人物正脸的视频',
					icon: 'none'
				})
				uni.showActionSheet({
					title: "选择上传类型",
					itemList: ['图片', '视频'],
					success: (res) => {
						this.state = res.tapIndex
						if (res.tapIndex == 0) {
							this.chooseImages()
						} else {
							this.chooseVideo()
						}
					}
				})
			},

tapIndex==0上传图片 1上传视频

上传图片

chooseImages() {
				var that = this;

				uni.chooseImage({
					count: 1, //默认1
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: function(res) {

						// that.imgLists = res.tempFilePaths[0]
						console.log(res);
						uni.uploadFile({
							url: '自己的后台地址',
							filePath: res.tempFilePaths[0],
							// 在电脑端运行把name,header 注掉,手机端要打开
							name: 'file', // 写死
							// 请求头一定要加,否则 iOS 图片上传会失败 安卓 可有可无
							header: {
								'content-type': 'multipart/form-data'
							},
							success: (respones) => {
								let le = JSON.parse(respones.data)
								that.urlMV = le.data

							}

						})
					}
				});

			},

上传视频

chooseVideo() {

				var that = this;
				uni.chooseVideo({
					count: 1,
					sourceType: ['camera', 'album'],
					success: function(res) {
						that.videoLists = res.tempFilePath
						uni.uploadFile({
							url: '上传自己地址',
							filePath: res.tempFilePath,
							name: 'file', // 写死
							// 请求头一定要加,否则 iOS 图片上传会失败 安卓 可有可无
							header: {
								'content-type': 'multipart/form-data'
							},
							success: (respones) => {
								let le = JSON.parse(respones.data)
								that.urlMV = le.data
							}

						})


					}
				});
			},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值