限制视频时长和大小

This commit is contained in:
丁杰 2026-05-06 15:01:38 +08:00
parent 659ec0f473
commit 3e9235844a
2 changed files with 30 additions and 22 deletions

View File

@ -429,8 +429,9 @@
icon: 'none' icon: 'none'
}); });
} else { } else {
console.error('上传失败:', err.errMsg);
uni.showToast({ uni.showToast({
title: '上传失败', title: err.errMsg || '上传失败',
icon: 'none' icon: 'none'
}); // }); //
} }

View File

@ -77,6 +77,21 @@ const handleUpload = async (userId, type, sourceType = ['album', 'camera'], uplo
// #ifdef APP-PLUS || MP-WEIXIN // #ifdef APP-PLUS || MP-WEIXIN
file = res; file = res;
// #endif // #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('file=======', file)
console.log('userId=======', userId) console.log('userId=======', userId)
// 检查文件大小 // 检查文件大小
if (uploadType == 'image') { if (uploadType == "image") {
if (file.size > 5 * 1024 * 1024) { if (file.size > 5 * 1024 * 1024) {
uni.showToast({ return Promise.reject({errMsg: "文件大小不能超过5MB"});
title: `文件大小不能超过5MB`,
icon: 'none'
})
return Promise.reject(new Error('文件大小超出限制'))
} }
} else if (uploadType == 'video') { } else if (uploadType == "video") {
if (file.size > 100 * 1024 * 1024) { if (file.size > 500 * 1024 * 1024) {
uni.showToast({ return Promise.reject({errMsg: "文件大小不能超过500MB"});
title: `文件大小不能超过100MB`,
icon: 'none'
})
return Promise.reject(new Error('文件大小超出限制'))
} }
} }