限制视频时长和大小
This commit is contained in:
parent
659ec0f473
commit
3e9235844a
|
|
@ -428,11 +428,12 @@
|
||||||
title: '取消上传',
|
title: '取消上传',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({
|
console.error('上传失败:', err.errMsg);
|
||||||
title: '上传失败',
|
uni.showToast({
|
||||||
icon: 'none'
|
title: err.errMsg || '上传失败',
|
||||||
}); // 新增:上传失败提示
|
icon: 'none'
|
||||||
|
}); // 新增:上传失败提示
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
|
|
@ -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,23 +164,15 @@ 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'
|
} else if (uploadType == "video") {
|
||||||
})
|
if (file.size > 500 * 1024 * 1024) {
|
||||||
return Promise.reject(new Error('文件大小超出限制'))
|
return Promise.reject({errMsg: "文件大小不能超过500MB"});
|
||||||
}
|
}
|
||||||
} else if (uploadType == 'video') {
|
}
|
||||||
if (file.size > 100 * 1024 * 1024) {
|
|
||||||
uni.showToast({
|
|
||||||
title: `文件大小不能超过100MB`,
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
return Promise.reject(new Error('文件大小超出限制'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let date = new Date().getTime()
|
let date = new Date().getTime()
|
||||||
console.log('file', file)
|
console.log('file', file)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue