文件上传服务获取InputStream未关闭,导致删除临时文件删除失败
parent
8dff14a6cc
commit
dce91a03ef
|
@ -8,9 +8,11 @@ import com.github.tobato.fastdfs.domain.fdfs.StorePath;
|
||||||
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
||||||
import com.ruoyi.common.core.utils.file.FileTypeUtils;
|
import com.ruoyi.common.core.utils.file.FileTypeUtils;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FastDFS 文件存储
|
* FastDFS 文件存储
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@ -27,7 +29,7 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FastDfs文件上传接口
|
* FastDfs文件上传接口
|
||||||
*
|
*
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
* @return 访问地址
|
* @return 访问地址
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -35,8 +37,10 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
|
||||||
@Override
|
@Override
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
public String uploadFile(MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(),
|
InputStream inputStream = file.getInputStream();
|
||||||
|
StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(),
|
||||||
FileTypeUtils.getExtension(file), null);
|
FileTypeUtils.getExtension(file), null);
|
||||||
|
inputStream.close();
|
||||||
return domain + "/" + storePath.getFullPath();
|
return domain + "/" + storePath.getFullPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,11 @@ import com.ruoyi.file.utils.FileUploadUtils;
|
||||||
import io.minio.MinioClient;
|
import io.minio.MinioClient;
|
||||||
import io.minio.PutObjectArgs;
|
import io.minio.PutObjectArgs;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minio 文件存储
|
* Minio 文件存储
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@ -23,8 +25,8 @@ public class MinioSysFileServiceImpl implements ISysFileService
|
||||||
private MinioClient client;
|
private MinioClient client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地文件上传接口
|
* Minio文件上传接口
|
||||||
*
|
*
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
* @return 访问地址
|
* @return 访问地址
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -33,13 +35,15 @@ public class MinioSysFileServiceImpl implements ISysFileService
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
public String uploadFile(MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
String fileName = FileUploadUtils.extractFilename(file);
|
String fileName = FileUploadUtils.extractFilename(file);
|
||||||
|
InputStream inputStream = file.getInputStream();
|
||||||
PutObjectArgs args = PutObjectArgs.builder()
|
PutObjectArgs args = PutObjectArgs.builder()
|
||||||
.bucket(minioConfig.getBucketName())
|
.bucket(minioConfig.getBucketName())
|
||||||
.object(fileName)
|
.object(fileName)
|
||||||
.stream(file.getInputStream(), file.getSize(), -1)
|
.stream(inputStream, file.getSize(), -1)
|
||||||
.contentType(file.getContentType())
|
.contentType(file.getContentType())
|
||||||
.build();
|
.build();
|
||||||
client.putObject(args);
|
client.putObject(args);
|
||||||
|
inputStream.close();
|
||||||
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
|
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue