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
}
})
}
});
},