chooseVideo() {
// 上传视频
uni.chooseVideo({
maxDuration: 30,
count: 1,
sourceType: ['camera', 'album'],
success: res => {
uni.showLoading({
title: '加载中'
});
this.paths = res.tempFilePath;
// let fileExtension = res.name.substring(res.name.lastIndexOf('.') + 1);
// let fileExtension
// if (res.name) {
// fileExtension = res.name.substring(res.name.lastIndexOf(".") + 1);
// fileExtension = fileExtension.toLowerCase();
// } else {
// fileExtension = res.tempFilePath.substring(res.tempFilePath.lastIndexOf(".") + 1);
// fileExtension = fileExtension.toLowerCase();
// }
// if (fileExtension == '3gp' || fileExtension == 'mp4' || fileExtension == 'rmvb' || fileExtension ==
// 'mov' || fileExtension == 'avi' || fileExtension == 'm4v') {
let that = this;
let as = myapi.newuploads;
// console.log(as);
uni.uploadFile({
url: that.$http.config.baseURL + myapi.newuploads +
'?AttachmentLevel=2&AttachmentType=3', //仅为示例,非真实的接口地址
filePath: res.tempFilePath,
name: 'file',
formData: {
'user': 'test'
},
success: (res) => {
let data = JSON.parse(res.data)
if (data.ResultCode == 200) {
uni.hideLoading();
uni.showToast({
title: '上传成功!',
icon: 'none',
duration: 2000
});
let imgd = data.DataList
that.videoList.push({
Id: imgd.Id,
FileUrl: this.$http.config.baseURL2 + imgd.FileUrl
})
} else {
uni.hideLoading();
uni.showToast({
title: ErrorMsg,
icon: 'none',
duration: 2000
});
}
},
fail: (res) => {
uni.hideLoading();
uni.showToast({
title: '上传错误',
icon: 'none',
duration: 2000
});
},
});
// that.$http.upload(myapi.newuploads, {
// filePath: res.tempFilePath,
// name: 'file',
// params: {
// AttachmentLevel: 2,
// AttachmentType: 3
// },
// })
// .then(res => {
// if (res.data.ResultCode == 200) {
// uni.hideLoading();
// uni.showToast({
// title: '上传成功!',
// icon: 'none',
// duration: 2000
// });
// let imgd = res.data.DataList
// that.videoList.push({
// Id: imgd.Id,
// FileUrl: this.$http.config.baseURL2 + imgd.FileUrl
// })
// } else {
// uni.showToast({
// title: res.ErrorMsg,
// icon: 'none',
// duration: 2000
// });
// }
// })
// .catch(err => {
// this.errs = JSON.stringify(err);
// // console.log(err);
// });
// } else {
// uni.showToast({
// title: '暂不支持该格式文件',
// icon: 'none',
// duration: 2000
// });
// }
},
fail: () => {
// uni.showToast({
// title: '视频错误',
// icon: 'none',
// duration: 2000
// });
},
});
}
2 个回复
5***@qq.com (作者) - 简洁,敏捷,高效,复用,自律
一个打开系统视频时,部分无法预览;还有一部分是选择系统内的视频,无法上传
5***@qq.com (作者) - 简洁,敏捷,高效,复用,自律