// 获取 minioClient getMinioClient(tempuser){ this.minioClient = new Minio.Client({ endPoint: '172.16.1.16', port: 9000, useSSL: false, region: 'kyc', accessKey: tempuser.accessKey, secretKey: tempuser.secretKey, sessionToken: tempuser.sessionToken, }); },
handleMinio() { let size = 0 let _this = this; let url = [{src: ""},{src: ""},{src: ""},{src: ""},{src: ""},{src: ""}]; let images = ["images/1.jpg", "images/2.jpg", "images/3.jpg", "images/4.jpg", "images/5.jpg", "images/6.jpg"]; for (let i = 0; i < images.length; i++) { loadNext(i); } async function loadNext(e) { //获取文件 let chunks = []; await new Promise((resolve, reject) => { _this.minioClient.getObject('kyc', images[e], function(err, dataStream) { if (err) { return console.log(err) } dataStream.on('data', function(chunk) { size += chunk.length; chunks = mergeTypedArrays(chunks, chunk); }) dataStream.on('end', function() { console.log('End. Total size = ' + size) // 保存文件 // saveFile(e+".jpg", "image/jpeg", chunks); // 转b64encoded图片 var b64encoded = btoa(String.fromCharCode.apply(null, chunks)); let src = 'data:image/jpeg;base64,' + b64encoded; url[e].src = src; }) dataStream.on('error', function(err) { console.log(err) }) }) }); } this.imgurl = url; function mergeTypedArrays(a, b) { if(!a && !b) throw '请为a和b指定有效参数。'; if(!b || b.length === 0) return a; if(!a || a.length === 0) return b; // 确保两个类型化数组的类型相同 if(Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) throw 'a和b参数类型不匹配。'; var c = new a.constructor(a.length + b.length); c.set(a); c.set(b, a.length); return c; } },
/** * 下载数据文件文件 * @param {String} path - 文件地址 * @param {String} name - 文件名,eg: test.png */ export const saveFile = (name, type, data) => { if (data !== null && navigator.msSaveBlob) { return navigator.msSaveBlob(new Blob([data], { type: type }), name); } var a = document.createElement('a'); a.style.display = "none"; var url = window.URL.createObjectURL(new Blob([data], {type: type})); a.setAttribute("href", url); a.setAttribute("download", name); document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); a.remove(); }