minio上传特别慢、上传文件不对?

 async minioUpload(contentFile) {
               this.$myHttp({
                  method: 'get',
                  url: `${this.prefix}/doc/sysAttach/getFrontUploadMinioAttach?fileName=${contentFile.name}&fileSize=${contentFile.size}`,
                  data: '',
                  headers: { 'Authorization': 'Sys ' + sessionStorage.getItem('token'),  'showLoading':'false' }
                }).then((res) => {
                    const data = res.data
                    this.minioUploadMth(data,contentFile)
                  })
                  .catch((error) => {
                   this.$message.error(error)
                  })
            },
            minioUploadMth(data,contentFile){
              console.log('contentFile')
              const minioClient = new Minio.Client({
                endPoint: '192.168.209.93',
                port: 9999,
                useSSL: false, // 是否使用ssl
                accessKey: 'minioadmin',
                secretKey: 'minioadmin'
              })
            let that=this
            this.getFileStream(contentFile).then((fileStream)=>{
              console.log('123------',contentFile)
              console.log("--------------",data.attachPath, fileStream, contentFile.size, contentFile.type)
              minioClient.putObject('no-version-bucket', data.attachPath, fileStream, contentFile.size, null, function(err, etag) {
                //1002: 上传成功, 1003: 上传失败
                let tempTransferStatus=null
                if (err){
                  console.log('minio上传',err, etag)
                  tempTransferStatus=1003
                  that.$message.error(err)
                  return
                } 
                  console.log('File uploaded successfully.');
                  tempTransferStatus=1002
                  //上传成功告诉后台
                  that.$myHttp({
                  method: 'post',
                  url: `${that.prefix}/doc/sysAttach/updateTransStatus`,
                  data: {
                    id:data.id,
                    transferStatus:tempTransferStatus
                  },
                  headers: { 'Authorization': 'Sys ' + sessionStorage.getItem('token'),  'showLoading':'false' }
                })
              })
            })
              
          },
          getFileStream(file) {
            return new Promise((resolve, reject) => {
              let reader = new FileReader()
              reader.readAsText(file)// 将文件转换为字符串
              reader.onload = (e) => { 
                resolve(reader.result)
              }
              reader.onerror = () => { // 文件读取失败时触发
                reject(reader.error)
              }
        
          },

getFileStream光将文件转换为字符串就需要特别长的时间,再到切片,而且上传上去的文件比原来大了,再下载下来也不对

阅读 3.8k
2 个回答

首先这个网络带宽确认是不是限制了,然后再下载下来不对,是哪不对,是无法正常使用还是怎么了

看看这个例子:TypeScript前端上传文件到MinIO实例
或者用Blob,fetch的API会自动处理文件流,不用你手动读文件内容:

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,
  });
};
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏