主题
LimeChooseFile 文件选择组件
一个基于UTS实现的文件选择插件,参考小程序chooseFile API实现,用法保持一致。支持安卓、iOS、鸿蒙和H5平台。提供了选择图片、视频和其他文件类型的功能。组件提供了简单易用的API,使开发者能够方便地在应用中集成文件选择功能。
文档链接
📚 组件详细文档请访问以下站点:
安装方法
代码演示
UNIAPPX 使用方式
ts
import { chooseFile, type ChooseFileOption } from '@/uni_modules/lime-choose-file'
const images = ref<string[]>([])
const onClick = () => {
chooseFile({
filename: 'xxxx', // 可选 用于给文件重命名(安卓、iOS)
type: 'image',
success(res){
images.value = res.tempFiles.map((item):string => item.path)
console.log('选择结果:', res.tempFiles)
},
fail(err){
console.log('选择失败:', err)
}
} as ChooseFileOption)
}UNIAPP 使用方式
ts
import { chooseFile } from '@/uni_modules/lime-choose-file'
const images = ref<string[]>([])
const onClick = () => {
chooseFile({
filename: 'xxxx', // 可选 用于给文件重命名(安卓、iOS)
type: 'image',
success(res){
images.value = res.tempFiles.map((item):string => item.path)
console.log('选择结果:', res.tempFiles)
},
fail(err){
console.log('选择失败:', err)
}
})
}API文档
chooseFile 方法
| 参数 | 说明 | 类型 | 必填 |
|---|---|---|---|
| options | 文件选择选项 | ChooseFileOption | 是 |
ChooseFileOption 选项
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| filename | string | 否 | 指定文件名,用于给文件重命名(安卓、iOS) |
| count | number | 否 | 最多可以选择的文件数量,默认为100 |
| type | string | 否 | 所选文件类型,默认为'all' |
| extension | string[] | 否 | 根据文件拓展名过滤,每一项都不能是空字符串。默认不过滤。仅H5支持 |
| success | (result: ChooseFileSuccessCallbackResult) => void | 否 | 接口调用成功的回调函数 |
| fail | (res: GeneralCallbackResult) => void | 否 | 接口调用失败的回调函数 |
| complete | (res: GeneralCallbackResult) => void | 否 | 接口调用结束的回调函数 |
ChooseFileSuccessCallbackResult 返回参数
| 参数 | 类型 | 说明 |
|---|---|---|
| tempFiles | ChooseFile[] | 返回选择的文件的本地临时文件对象数组 |
| errMsg | string | 错误信息 |
ChooseFile 对象结构
| 参数 | 类型 | 说明 |
|---|---|---|
| name | string | 选择的文件名称 |
| path | string | 本地临时文件路径 (本地路径) |
| size | number | 本地临时文件大小,单位 B |
| time | number | 选择的文件的会话发送时间,Unix时间戳 |
| type | 'video' | 'image' | 'file' | 'all' | 选择的文件类型 |
文件类型说明
| 类型值 | 说明 |
|---|---|
| video | 视频文件 |
| image | 图片文件 |
| file | 除图片和视频外的其他文件 |
| all | 所有类型文件 |
功能特点
- 支持多种文件类型的选择,包括图片、视频和其他文件
- 支持文件重命名功能
- 兼容安卓、iOS、鸿蒙和H5平台
- 提供简单易用的API接口
- 支持指定最大选择数量
- 支持文件扩展名过滤(H5平台)
常见问题
- iOS路径是中文时无法上传到服务器,这时候需要设置
filename给文件重命名 - APP端需要自定义基座才能使用
- 文件选择后会返回临时文件路径,需要及时使用或保存
- H5端可以通过extension参数过滤文件类型
支持与赞赏
如果你觉得本插件解决了你的问题,可以考虑支持作者:
| 支付宝赞助 | 微信赞助 |
|---|---|
![]() | ![]() |

