// 封装上传文件的方法 http://121.5.37.142:9001/browser/file-upload 后台查看的网址 import AWS from 'aws-sdk' // 地址路径 let endpoint: string = 'http://121.5.37.142:9000' // 账号 let accessKeyId: string = 'admin' // 密码 let secretAccessKey: string = 'minio123456' // 上传文件的基础配置 const s3 = new AWS.S3({ endpoint: endpoint, accessKeyId: accessKeyId, secretAccessKey: secretAccessKey, region: 'us-east-1', // 写死就行 s3ForcePathStyle: true }); // 上传图片的方法 // 传入的 肯定是一个 proform 的 上传图片的数组格式 export async function handleMinIOUpload(fileList: any) { let fileRes: any = [] for (let i = 0; i < fileList.length; i++) { let file: any = fileList[i] const key = `${new Date().getTime()} ${file.name.toString()}`; const result = await s3.upload({ Bucket: 'file-upload', Key: key, Body: file.originFileObj, }).promise(); console.log('上传成功:', result); fileRes.push({ name: file.name.toString(), key: key, url: result.Location }) } return fileRes }; // 删除图片的方法 export async function handleMinIODelete(fileKey: string) { // 文件的key名称 const result = await s3.deleteObject({ Bucket: 'file-upload', // 你的桶名 Key: fileKey, // 上传时的文件名(路径+文件名) }).promise(); return result } // 读取文件 export async function handleMinIOPriview(fileName: string[]) { let resultList = [] for (let i = 0; i < fileName.length; i++) { const url = await s3.getSignedUrlPromise('getObject', { Bucket: 'file-upload', Key: fileName[i], Expires: 3600 }); resultList.push({ url: url, name: fileName[i] }) } return resultList // window.open(url); }