更新记录
1.0.0(2026-06-07) 下载此版本
v1.0.0 (2026-06-07)
- ✨ 初始版本发布
平台兼容性
uni-app(5.0)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | √ | - | - | - | - | - | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
📖 简介
`aura-upload-cloud` 是一个专为 uniCloud 设计的文件上传组件,支持图片、视频、音频等多种文件类型,提供网格/列表两种展示模式,开箱即用。
✨ 特性
- 📸 多类型支持 - 图片、视频、音频、文件
- ☁️ uniCloud 云存储 - 自动上传到云存储空间
- 🎨 双布局模式 - 网格布局(图片/视频)/ 列表布局(音频/文件)
- 📱 多端兼容 - 支持 App、H5、各小程序平台
- 🔄 上传进度 - 实时显示上传进度
- 🖼️ 在线预览 - 图片预览、视频播放、音频播放
- 🔁 失败重试 - 上传失败自动重试
- 🗑️ 删除回调 - 支持自定义删除逻辑
- ⚙️ 高度可配置 - 丰富的配置选项
📦 安装
通过插件市场安装
- 在 DCloud 插件市场搜索 `aura-upload-cloud`
- 点击「使用 HBuilderX 导入插件」
- 选择你的项目,点击确定
准备工作
确保你的项目已满足以下条件:
✅ 已启用 uniCloud 并关联服务空间
✅ 已配置云存储权限
✅ HBuilderX 版本 >= 3.1.0
🚀 快速开始
基础用法
<template>
<view>
<!-- 图片上传(网格布局) -->
<aura-upload-cloud
v-model="images"
upload-dir="avatar"
file-type="image"
:max-count="9"
:columns="4"
/>
<!-- 已上传的文件ID列表 -->
<view>已上传:{{ images.length }} 张图片</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
const images = ref([])
</script>
视频上传
<template>
<aura-upload-cloud
v-model="videos"
upload-dir="videos"
file-type="video"
:max-count="3"
/>
</template>
<script setup>
import { ref } from 'vue'
const videos = ref([])
</script>
音频上传
<template>
<aura-upload-cloud
v-model="audios"
upload-dir="audios"
file-type="audio"
:max-count="5"
/>
</template>
<script setup>
import { ref } from 'vue'
const audios = ref([])
</script>
📋 API
Props
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|---|---|---|---|---|
| modelValue / v-model | 已上传的文件ID数组 | Array | [] |
- |
| uploadDir | 上传目录(云存储路径) | String | '' |
- |
| maxCount | 最大上传数量 | Number | 9 |
1-99 |
| fileType | 文件类型 | String | 'image' |
image / video / audio / file |
| columns | 网格列数(仅图片/视频) | Number | 4 |
1-6 |
| showRemove | 是否显示删除按钮 | Boolean | true |
true / false |
| showAddBtn | 是否显示添加按钮 | Boolean | true |
true / false |
| autoUpload | 是否自动上传 | Boolean |
准备工作
确保你的项目已满足以下条件:
✅ 已启用 uniCloud 并关联服务空间
✅ 已配置云存储权限
✅ HBuilderX 版本 >= 3.1.0
🚀 快速开始
基础用法
<template>
<view>
<!-- 图片上传(网格布局) -->
<aura-upload-cloud
v-model="images"
upload-dir="avatar"
file-type="image"
:max-count="9"
:columns="4"
/>
<!-- 已上传的文件ID列表 -->
<view>已上传:{{ images.length }} 张图片</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
const images = ref([])
</script>
视频上传
<template>
<aura-upload-cloud
v-model="videos"
upload-dir="videos"
file-type="video"
:max-count="3"
/>
</template>
<script setup>
import { ref } from 'vue'
const videos = ref([])
</script>
音频上传
<template>
<aura-upload-cloud
v-model="audios"
upload-dir="audios"
file-type="audio"
:max-count="5"
/>
</template>
<script setup>
import { ref } from 'vue'
const audios = ref([])
</script>
📋 API
Props
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|---|---|---|---|---|
| modelValue / v-model | 已上传的文件ID数组 | Array | [] |
- |
| uploadDir | 上传目录(云存储路径) | String | '' |
- |
| maxCount | 最大上传数量 | Number | 9 |
1-99 |
| fileType | 文件类型 | String | 'image' |
image / video / audio / file |
| columns | 网格列数(仅图片/视频) | Number | 4 |
1-6 |
| showRemove | 是否显示删除按钮 | Boolean | true |
true / false |
| showAddBtn | 是否显示添加按钮 | Boolean | true |
true / false |
| autoUpload | 是否自动上传 | Boolean | true |
true / false |
| maxSize | 文件大小限制(MB) | Number | 10 |
1-500 |
| multiple | 是否支持多选 | Boolean | false |
true / false |
| compressImage | 是否压缩图片 | Boolean | true |
true / false |
| compressQuality | 图片压缩质量 | Number | 0.8 |
0-1 |
| compressVideo | 是否压缩视频 | Boolean | true |
true / false |
| maxRetries | 最大重试次数 | Number | 3 |
0-5 |
| beforeUpload | 上传前的校验函数 | Function | null |
- |
| customFileName | 自定义文件名生成函数 | Function | null |
- |
| debug | 是否开启调试日志 | Boolean | false |
true / false |
Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| update:modelValue | 文件列表变化时触发 | (fileIDs: Array) |
| change | 文件列表变化时触发 | (fileIDs: Array) |
| success | 上传成功时触发 | ({ file, index }) |
| error | 上传失败时触发 | ({ error, file, index }) |
| progress | 上传进度更新时触发 | ({ file, progress, index }) |
| remove | 删除文件时触发 | ({ file, index, fileID, url }) |
| remove-success | 云文件删除成功时触发 | ({ fileID }) |
| remove-error | 云文件删除失败时触发 | ({ error, fileID }) |
Methods
通过 ref 调用组件方法:
| 方法名 | 说明 | 参数 |
|---|---|---|
uploadWaitingFiles() |
手动上传等待中的文件 | 无 |
clearAll() |
清空所有文件 | 无 |
getFileList() |
获取当前文件列表 | 无 |
💡 高级用法
自定义删除逻辑
<template>
<aura-upload-cloud
v-model="files"
@remove="handleRemove"
/>
</template>
<script setup>
const handleRemove = async ({ fileID }) => {
// 调用你自己的云函数删除
// 云函数实例
<!-- const removeCloudFile = async (fileIDs = []) => {
if (!Array.isArray(fileIDs) || !fileIDs.length) return null
return uniCloud.deleteFile({
fileList: fileIDs
})
} -->
// 云方法
const res = await uniCloud.callFunction({
name: 'removeCloudFile',
data: { fileID }
})
// 或云对象
<!-- const contentObjCo = uniCloud.importObject('my-content')
contentObjCo.removeCloudFile(fileIDs) -->
if (res.code === 0) {
uni.showToast({ title: '删除成功' })
}
}
</script>
上传前校验
<template>
<aura-upload-cloud
v-model="files"
:before-upload="validateFile"
/>
</template>
<script setup>
const validateFile = (file) => {
// 文件大小校验
if (file.size > 5 * 1024 * 1024) {
uni.showToast({ title: '文件不能超过5MB', icon: 'none' })
return false
}
// 文件类型校验
const ext = file.name.split('.').pop()
if (!['jpg', 'png', 'jpeg'].includes(ext)) {
uni.showToast({ title: '只支持 JPG/PNG 格式', icon: 'none' })
return false
}
return true
}
</script>
自定义文件名
<template>
<aura-upload-cloud
v-model="files"
:custom-file-name="generateFileName"
/>
</template>
<script setup>
const generateFileName = (file, ext) => {
// 返回自定义的文件名
const timestamp = Date.now()
const userId = uni.getStorageSync('userId')
return \`${userId}/${timestamp}.${ext}\`
}
</script>
手动上传控制
<template>
<view>
<aura-upload-cloud
ref="uploadRef"
v-model="files"
:auto-upload="false"
/>
<button @click="handleUpload">开始上传</button>
<button @click="handleClear">清空所有</button>
</view>
</template>
<script setup>
import { ref } from 'vue'
const uploadRef = ref(null)
const files = ref([])
const handleUpload = () => {
uploadRef.value?.uploadWaitingFiles()
}
const handleClear = () => {
uploadRef.value?.clearAll()
}
</script>
🔧 注意事项
- uniCloud 配置
确保项目已关联 uniCloud 服务空间,云存储需要开通并配置权限。 - 小程序配置
需要在后台配置 uploadFile 合法域名,开发者工具中关闭「不校验合法域名」选项。 - H5 配置
需要在 uniCloud Web 控制台配置安全域名,跨域问题请检查服务端配置。
📝 更新日志
v1.0.0 (2026-06-07)
- ✨ 初始版本发布
- 🎉 支持图片、视频、音频上传
- 🎨 支持网格/列表双布局
- 📱 支持多平台(App、H5、小程序)
- 🔄 支持上传进度显示
- 🖼️ 支持图片/视频预览
- 🎵 支持音频在线播放
- 🔁 支持失败重试
- 🗑️ 支持删除回调

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