vue项目Minio上传附件记录

1.初始化Minio

创建minio.js文件

import { getOssSign } from '@/api/upload'

// 初始化minioClient
var Minio = require('minio')
export function initMinio () {
    return new Promise((resolve, reject) => {
        let localMinio = JSON.parse(localStorage.getItem('os'))
        if (localMinio) {
            let minioObj = {
                endPoint: 'oss.shlgbj.gov.cn',
                // port: 9200,
                useSSL: true,
                accessKey: localMinio.accessid,
                secretKey: localMinio.accesskey
            }
            var minioClient = newMinio(minioObj)
            resolve(minioClient)
        } else {
            let param = { ossType: 'minio' }
            getOssSign(param).then(response => {
                let minioDeploy = response.data
                let minioObj = {
                    endPoint: 'oss.shlgbj.gov.cn',
                    // endPoint: '10.0.51.96',
                    // port: 9200,
                    useSSL: true,
                    accessKey: minioDeploy.accessid,
                    secretKey: minioDeploy.accesskey
                    // accessKey: 'minioadmin',
                    // secretKey: 'minioadmin'
                }
                localStorage.setItem('os', JSON.stringify(minioDeploy))
                var minioClient = newMinio(minioObj)
                resolve(minioClient)
            }).catch(error => {
                console.log(error)
                reject()
            })
        }
    })
}

export const newMinio = (minioObj) => {
    return new Minio.Client(minioObj)
}

2.fileUpload组件使用Minio





一些坑:

  1. 使用node的stream模块将file进行了可读流的转化,至今不知为啥可以用;
  2. 给每个上传附件自定义进度条的时候,set(vm.fileList, vm.fileList.length - 1, curItem)
  3. 上传中fileList展示区域,本质上是本地文件的进度状态,
    成功之后展示已上传的文件信息,此处需要删除上传时放入数组的file对象 this.fileList.pop()

你可能感兴趣的:(vue项目Minio上传附件记录)