上传文件限制大小

This commit is contained in:
2024-09-10 13:47:09 +08:00
parent 7d81e7d4d5
commit 3def3bf68b
3 changed files with 8 additions and 2 deletions

View File

@@ -39,6 +39,7 @@ Page({
})
},
async upload(res) {
const result = await uploadPublicFile(res.tempFiles[0]?.tempFilePath)
if (result.statusCode !== 200) {
alertInfo("上传失败")
@@ -55,6 +56,12 @@ Page({
mediaType: ['image'], // 可以选择文件的类型,这里只允许上传文件
sourceType: ['album', 'camera'],
success: (res) => {
const file = res.tempFiles[0];
if (file.size / 1024 / 1024 > 1) {
alertInfo("文件不能大于1M")
return;
}
// console.log('res', res)
loadingFunc(async () => {
await this.upload(res)
})