springboot 调用 minio出现Software caused connection abort: socket write error

springboot 调用 minio Software caused connection abort: socket write error

代码如下

  String catalog="";
        if(!StringUtils.isEmpty(fileDTO.getPrefix())){
            catalog=fileDTO.getGroupName()+fileDTO.getPrefix();
        }else{
            Date nowDate=new Date();
            catalog= fileDTO.getGroupName()+DateUtils.generatorThreeeDir(nowDate);
        }
        fullFileName=catalog.replaceAll("\\\\","/")+File.separator+fileName;
        String contentType = HttpServletUtils.getMimeType(originalFilename);//file.getContentType();
        String tempfileName=filePathConfig.getUploadTmpPath()+File.separator+fullFileName;

            FileUtils.saveMultiFile(file,tempfileName);
            //新方法
            minioClient.uploadObject(UploadObjectArgs.builder()
                    .bucket(fileDTO.getBucketName())
                    .object(fullFileName)
                    .filename(tempfileName).contentType(contentType)
                    .build());

 

原因是object() 是一个url地址,而我在windows服务器上 fullFileName 里面含有File.separator  会变成\,会造成原因失败,改成/就行了

所以改成

  String catalog="";
        if(!StringUtils.isEmpty(fileDTO.getPrefix())){
            catalog=fileDTO.getGroupName()+fileDTO.getPrefix();
        }else{
            Date nowDate=new Date();
            catalog= fileDTO.getGroupName()+DateUtils.generatorThreeeDir(nowDate);
        }
        fullFileName=catalog.replaceAll("\\\\","/")+"/"+fileName;
        String contentType = HttpServletUtils.getMimeType(originalFilename);//file.getContentType();
        String tempfileName=filePathConfig.getUploadTmpPath()+File.separator+fullFileName;
     
            FileUtils.saveMultiFile(file,tempfileName);
            //新方法
            minioClient.uploadObject(UploadObjectArgs.builder()
                    .bucket(fileDTO.getBucketName())
                    .object(fullFileName)
                    .filename(tempfileName).contentType(contentType)
                    .build());

 

posted @ 2025-07-24 19:05  ☆♂安♀★  阅读(22)  评论(0)    收藏  举报