新增两种存储对象

uat_us
熊飞 2024-01-11 14:41:54 +08:00
parent 343b9c25e5
commit 95f68a1fb1
4 changed files with 77 additions and 6 deletions

View File

@ -3,7 +3,7 @@
"version": "1.0.0",
"scripts": {
"dev": "vue-cli-service serve --open",
"build": "vue-cli-service --max_old_space_size=10000 build",
"build": "vue-cli-service build",
"build:prod": "vue-cli-service build --mode prod",
"build:uat": "vue-cli-service build --mode uat",
"build:usa": "vue-cli-service build --mode usa",

View File

@ -102,7 +102,8 @@ export default {
return ~this.$path.indexOf(v.Code)
})
this.tableData = Object.assign([], tableData)
console.log(this.tableData)
console.log(JSON.stringify(this.$path))
console.log(JSON.stringify(this.tableData))
}
}
}

View File

@ -1,5 +1,8 @@
const OSS = require('ali-oss')
import Minio from 'minio'
const Minio = require('minio')
const stream = require('stream')
console.log(Minio)
import Vue from 'vue'
const { GenerateSTS, GetObjectStoreToken } = require('../api/user.js')
import { getToken } from '@/utils/auth'
@ -7,21 +10,87 @@ import { getToken } from '@/utils/auth'
Vue.prototype.OSSclientConfig = {
}
function blobToBuffer(blob, fileName) {
return new Promise((resolve, reject) => {
const file = new File([blob], fileName);
resolve(file)
})
}
async function ossGenerateSTS() {
let res = await GetObjectStoreToken()
Vue.prototype.OSSclientConfig = { ...res.Result[res.Result.ObjectStoreUse] }
let ObjectStoreUse = 'AWS'
// Vue.prototype.OSSclientConfig = { ...res.Result[res.Result.ObjectStoreUse] }
Vue.prototype.OSSclientConfig = { ...res.Result[ObjectStoreUse] }
Vue.prototype.OSSclientConfig.basePath = Vue.prototype.OSSclientConfig.viewEndpoint
// let minioClient = new Minio.Client(Vue.prototype.OSSclientConfig);
switch (res.Result.ObjectStoreUse) {
// switch (res.Result.ObjectStoreUse) {
switch (ObjectStoreUse) {
case 'AliyunOSS':
Vue.prototype.OSSclientConfig.bucket = Vue.prototype.OSSclientConfig.bucketName
Vue.prototype.OSSclient = new OSS(Vue.prototype.OSSclientConfig)
break
case 'MinIO':
let minioClient = new Minio.Client(Vue.prototype.OSSclientConfig);
// Vue.prototype.OSSclient = new OSS(Vue.prototype.OSSclientConfig)
Vue.prototype.OSSclient = {
put: function (objectName, object) {
return new Promise(async (resolve, reject) => {
try {
var name = objectName.split('/')[objectName.split('/').length - 1]
const reader = new FileReader();
reader.onload = (ex) => {
const bufferStream = new stream.PassThrough()
bufferStream.end(Buffer.from(ex.target.result))
minioClient.putObject(Vue.prototype.OSSclientConfig.bucketName, objectName, bufferStream, function(err,etag) {
if (err) {
console.log(err)
reject()
} else {
resolve({
name: objectName,
url: 'http://www.abc.com' + objectName
})
}
})
};
reader.readAsArrayBuffer(object);
} catch (e) {
console.log(e)
}
})
}
}
break
case 'AWS':
let aws = new Minio.Client(Vue.prototype.OSSclientConfig);
Vue.prototype.OSSclient = {
put: function (objectName, object) {
return new Promise(async (resolve, reject) => {
try {
var name = objectName.split('/')[objectName.split('/').length - 1]
const reader = new FileReader();
reader.onload = (ex) => {
const bufferStream = new stream.PassThrough()
bufferStream.end(Buffer.from(ex.target.result))
aws.putObject(Vue.prototype.OSSclientConfig.bucketName, objectName, bufferStream, function(err,etag) {
if (err) {
console.log(err)
reject()
} else {
resolve({
name: objectName,
url: 'http://www.abc.com' + objectName
})
}
})
};
reader.readAsArrayBuffer(object);
} catch (e) {
console.log(e)
}
})
}
}
}
return
}

View File

@ -234,6 +234,7 @@ export default {
this.loading = true
var file = await this.fileToBlob(param.file)
const trialId = this.$route.query.trialId
console.log(this.OSSclient.put)
const res = await this.OSSclient.put(`/${trialId}/DocumentToSign/${param.file.name}`, file)
this.fileList.push({ name: param.file.name, path: this.$getObjectName(res.url), url: this.$getObjectName(res.url) })
this.form.Path = this.$getObjectName(res.url)