为了配合MinIO安全改造,图片上传组件 ImageUpload/index.vue 已经进行了安全升级,支持bucket密码验证和预签名URL机制。
:http-request="customUpload" 替代默认上传interface Props {
// ... 原有参数 ...
// bucket访问密码
bucketPassword?: string;
// 是否启用bucket密码验证
enablePasswordValidation?: boolean;
}
<template>
<ImageUpload
v-model="imageList"
:limit="5"
:file-size="10"
:file-type="['png', 'jpg', 'jpeg']"
/>
</template>
<template>
<ImageUpload
v-model="imageList"
:limit="5"
:file-size="10"
:file-type="['png', 'jpg', 'jpeg']"
:enable-password-validation="true"
:bucket-password="bucketPassword"
/>
</template>
<script setup>
import { ref } from 'vue'
const imageList = ref([])
const bucketPassword = ref('your_bucket_password')
</script>
<template>
<ImageUpload
v-model="imageList"
:limit="5"
:file-size="10"
:file-type="['png', 'jpg', 'jpeg']"
:enable-password-validation="true"
/>
</template>
<script setup>
import { ref } from 'vue'
const imageList = ref([])
// 不传入bucketPassword,组件会自动弹出密码输入对话框
</script>
enablePasswordValidation=true 且 bucketPassword 有值时bucket-password 参数enablePasswordValidation=true 且 bucketPassword 为空时// 直接上传到 /resource/oss/upload
const uploadImgUrl = baseUrl + '/resource/oss/upload'
// 使用自定义上传方法
const customUpload = async (options) => {
const formData = new FormData()
formData.append('file', options.file)
const response = await fetch(uploadImgUrl.value, {
method: 'POST',
headers: {
...headers.value,
'bucket-password': bucketPassword || passwordForm.bucketPassword || ''
},
body: formData
})
// 处理响应...
}
const handlePictureCardPreview = async (file) => {
try {
if (file.ossId) {
// 使用安全预览机制
dialogImageUrl.value = file.url // 简化处理,实际应调用安全预览API
} else {
// 直接使用URL预览
dialogImageUrl.value = file.url
}
dialogVisible.value = true
} catch (error) {
console.error('预览失败:', error)
proxy?.$modal.msgError('预览失败')
}
}
bucket-password 请求头{ code: 200, data: { fileName, url, ossId } }enable-password-validation="true" 属性bucket-password 属性或对话框输入<!-- 旧版本 -->
<ImageUpload v-model="images" />
<!-- 新版本(启用密码验证) -->
<ImageUpload
v-model="images"
:enable-password-validation="true"
:bucket-password="bucketPassword"
/>
更新时间: 2025-01-27
版本: v2.0.0
维护者: 开发团队