限制视频时长和大小
This commit is contained in:
parent
659ec0f473
commit
3e9235844a
|
|
@ -429,8 +429,9 @@
|
|||
icon: 'none'
|
||||
});
|
||||
} else {
|
||||
console.error('上传失败:', err.errMsg);
|
||||
uni.showToast({
|
||||
title: '上传失败',
|
||||
title: err.errMsg || '上传失败',
|
||||
icon: 'none'
|
||||
}); // 新增:上传失败提示
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,6 +77,21 @@ const handleUpload = async (userId, type, sourceType = ['album', 'camera'], uplo
|
|||
// #ifdef APP-PLUS || MP-WEIXIN
|
||||
file = res;
|
||||
// #endif
|
||||
const duration = res.duration;
|
||||
if (duration < 3) {
|
||||
uni.showToast({
|
||||
title: "视频时长不能少于3秒",
|
||||
icon: "none",
|
||||
});
|
||||
return null;
|
||||
}
|
||||
if (duration > 59.9) {
|
||||
uni.showToast({
|
||||
title: "视频时长不能超过1分钟",
|
||||
icon: "none",
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -149,21 +164,13 @@ const uploadFile = async (file, userId, type, uploadType) => {
|
|||
console.log('file=======', file)
|
||||
console.log('userId=======', userId)
|
||||
// 检查文件大小
|
||||
if (uploadType == 'image') {
|
||||
if (uploadType == "image") {
|
||||
if (file.size > 5 * 1024 * 1024) {
|
||||
uni.showToast({
|
||||
title: `文件大小不能超过5MB`,
|
||||
icon: 'none'
|
||||
})
|
||||
return Promise.reject(new Error('文件大小超出限制'))
|
||||
return Promise.reject({errMsg: "文件大小不能超过5MB"});
|
||||
}
|
||||
} else if (uploadType == 'video') {
|
||||
if (file.size > 100 * 1024 * 1024) {
|
||||
uni.showToast({
|
||||
title: `文件大小不能超过100MB`,
|
||||
icon: 'none'
|
||||
})
|
||||
return Promise.reject(new Error('文件大小超出限制'))
|
||||
} else if (uploadType == "video") {
|
||||
if (file.size > 500 * 1024 * 1024) {
|
||||
return Promise.reject({errMsg: "文件大小不能超过500MB"});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue