minio上传大文件特变慢?

  minioUploadMth(data, contentFile) {

this.$loading({

background: 'rgba(0, 0, 0, 0.05)'

})

const minioClient = new Minio.Client({

endPoint: '',

port: ,

useSSL: false, // 是否使用ssl

accessKey: 'minioadmin',

secretKey: 'minioadmin'

})

let that = this

let reader = new FileReader()

reader.readAsArrayBuffer(contentFile)

reader.onload = function (e) {

let res = e.target.result //ArrayBuffer

let buf = Buffer.from(res) //Buffer

minioClient.putObject('no-version-bucket', data.attachPath, buf, contentFile.size, null, function (err, etag) {

//1002: 上传成功, 1003: 上传失败

let tempTransferStatus = null

if (err) {

tempTransferStatus = 1003

that.$message.error(err)

return

}

console.log('File uploaded successfully.');

tempTransferStatus = 1002

//上传成功告诉后台

that.$myHttp({

method: 'post',

url: `${that.prefix}/doc/sysAttach/updateTransStatus?id=${data.id}&transferStatus=${tempTransferStatus}`,

data: {} ,

headers: { 'Authorization': 'Sys ' + sessionStorage.getItem('token'), 'showLoading': 'false' }

}).then((res)=>{

if(res.code==200){

this.$message.success("大文件上传成功")

that.$loading().close()

}

}).catch(e=>{

that.$message.error("大文件上传成功")

that.$loading().close()

})

})

}

},

分别向minio服务器和自己的服务器上传,上传特别慢,自己的服务器接口测试的时候响应挺快,但是minio上传成后,向自己的服务器接口显示200,响应特别慢,没有返回结果


回答:

分片上传,MinIO客户端库通常提供了这个功能吧,还有你代码里用了FileReader来读取文件,然后再上传,这个过程就会消耗时间,你可以直接用文件流来上传,昨天不是贴了一个例子吗

const file = ref<File | null>(null);

const handleFileChange = (e: Event) => {

const target = e.target as HTMLInputElement;

file.value = target.files?.[0] || null;

};

const upload = async () => {

if (!file.value) return;

const presignedUrl = await getPresignedUrl(file.value.name, file.value.type);

await fetch(presignedUrl, {

method: 'PUT',

body: file.value,

});

};

https://github.com/tx7do/minio-typescript-example

以上是 minio上传大文件特变慢? 的全部内容, 来源链接: utcz.com/p/934752.html

回到顶部