更新记录
1.0.0(2025-11-10) 下载此版本
1、基础文件选择功能
平台兼容性
uni-app x(4.83)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| × | × | √ | √ | √ | × |
m-choose-file
uni-app UTS 插件,用于在 APP 平台选择文件。
平台支持
- ✅ Android
- ✅ iOS
- ✅ HarmonyOS
- ❌ 其他平台(会返回错误)
安装
将插件放置在 uni_modules 目录下即可。
使用方法
导入插件
import { onChooseFile } from '@/uni_modules/m-choose-file'
基本用法
// 选择单个文件
onChooseFile({
maxSelectNumber: 1
})
.then((res) => {
if(res.files.length){
console.log('选择的文件:', res.files)
}
})
.catch((err) => {
console.error('选择失败:', err)
})
选择多个文件
// 选择多个文件(最多5个)
onChooseFile({
maxSelectNumber: 5
})
.then((res) => {
if(res.files.length){
console.log('选择的文件:', res.files)
}
})
.catch((err) => {
console.error('选择失败:', err)
})
参数说明
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| maxSelectNumber | number | 否 | 1 | 最大选择文件数量 |
返回值
{
files: [
{
tempFilePath: string, // 文件临时路径
name: string, // 文件名
type: string, // 文件 MIME 类型
size: number // 文件大小(字节)
}
]
}
错误码
| 错误码 | 说明 |
|---|---|
| 9010001 | 文件选择失败 |
| 9010003 | 不支持该平台 |
完整示例
<template>
<button @click="chooseFile">选择文件</button>
</template>
<script setup>
import { onChooseFile } from '@/uni_modules/m-choose-file'
const chooseFile = () => {
onChooseFile({
maxSelectNumber: 1
})
.then((res) => {
if(res.files.length){
console.log('选择的文件:', res.files)
uni.showToast({ title: '选择成功', icon: 'success' })
}
})
.catch((err) => {
console.error('选择失败:', err)
uni.showToast({ title: '选择失败', icon: 'none' })
})
}
</script>

收藏人数:
下载插件并导入HBuilderX
赞赏(0)
下载 1
赞赏 0
下载 10844891
赞赏 1799
赞赏
京公网安备:11010802035340号