上传文件限制大小
This commit is contained in:
parent
7d81e7d4d5
commit
3def3bf68b
1
app.js
1
app.js
|
@ -8,7 +8,6 @@ App({
|
|||
onLaunch() {
|
||||
const { api } = getConfigByEnv();
|
||||
this.globalData = { ...this.globalData, api, }
|
||||
|
||||
},
|
||||
globalData: {
|
||||
primaryColor: '#52c41a'
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user