mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-03-12 03:36:51 +08:00
优化文件异常输入流未关闭的问题
This commit is contained in:
@@ -34,16 +34,27 @@ public class MinioSysFileServiceImpl implements ISysFileService
|
|||||||
@Override
|
@Override
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
public String uploadFile(MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
String fileName = FileUploadUtils.extractFilename(file);
|
InputStream inputStream = null;
|
||||||
InputStream inputStream = file.getInputStream();
|
try
|
||||||
PutObjectArgs args = PutObjectArgs.builder()
|
{
|
||||||
.bucket(minioConfig.getBucketName())
|
String fileName = FileUploadUtils.extractFilename(file);
|
||||||
.object(fileName)
|
inputStream = file.getInputStream();
|
||||||
.stream(inputStream, file.getSize(), -1)
|
PutObjectArgs args = PutObjectArgs.builder()
|
||||||
.contentType(file.getContentType())
|
.bucket(minioConfig.getBucketName())
|
||||||
.build();
|
.object(fileName)
|
||||||
client.putObject(args);
|
.stream(inputStream, file.getSize(), -1)
|
||||||
IoUtils.closeQuietly(inputStream);
|
.contentType(file.getContentType())
|
||||||
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
|
.build();
|
||||||
|
client.putObject(args);
|
||||||
|
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Minio Failed to upload file", e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IoUtils.closeQuietly(inputStream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user