上传文件限制大小

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

1
app.js
View File

@ -8,7 +8,6 @@ App({
onLaunch() {
const { api } = getConfigByEnv();
this.globalData = { ...this.globalData, api, }
},
globalData: {
primaryColor: '#52c41a'

View File

@ -9,7 +9,7 @@
<view class="page-mask" bindtap="hidePagePopup"></view>
<view class="page-popup">
<view class="page-popup-box">
<view class="page-line" wx:for="{{total}}" wx:for-index="idx" data-index="{{idx+1}}" bindtap="changePage">第{{item+1}}页</view>
<view class="page-line" wx:for="{{total}}" wx:key="index" wx:for-index="idx" data-index="{{idx+1}}" bindtap="changePage">第{{item+1}}页</view>
</view>
</view>
</view>

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)
})