f***@qq.com
f***@qq.com
  • 发布:2025-05-08 09:25
  • 更新:2025-05-08 10:06
  • 阅读:200

小程序无法限制文件类型

分类:HBuilderX

fileMediatype 设置 all
file-extname="doc,docx" 设置 文件类型
小程序中,选择文件没有限制,还是显示了所有

我查了 小程序的文件wx.chooseMessageFile 文档

type string 'all' 否 所选的文件的类型
合法值 说明
all 从所有文件选择
video 只能选择视频文件
image 只能选择图片文件
file 可以选择除了图片和视频之外的其它的文件
extension Array.<string> 否 根据文件拓展名过滤,仅 type==file 时有效。每一项都不能是空字符串。默认不过滤。

2025-05-08 09:25 负责人:无 分享
已邀请:
f***@qq.com

f***@qq.com (作者) - 范春

我把文件改了 node_modules\@dcloudio\uni-ui\lib\uni-file-picker\choose-and-upload-file.js

function chooseAll(opts) {  
    const {  
        count,  
        type,  
        extension  
    } = opts;  
    return new Promise((resolve, reject) => {  
        let chooseFile = uni.chooseFile;  
        if (typeof wx !== 'undefined' &&  
            typeof wx.chooseMessageFile === 'function') {  
            chooseFile = wx.chooseMessageFile;  
        }  
        if (typeof chooseFile !== 'function') {  
            return reject({  
                errMsg: ERR_MSG_FAIL + ' 请指定 type 类型,该平台仅支持选择 image 或 video。',  
            });  
        }  
        chooseFile({  
            type: type,  
            count,  
            extension,  
            success(res) {  
                resolve(normalizeChooseAndUploadFileRes(res));  
            },  
            fail(res) {  
                reject({  
                    errMsg: res.errMsg.replace('chooseFile:fail', ERR_MSG_FAIL),  
                });  
            },  
        });  
    });  
}

要回复问题请先登录注册