优化文件异常输入流未关闭的问题

pull/386/head
RuoYi 10 months ago
parent 2335157f6e
commit 92c6d21855

@ -37,10 +37,20 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
@Override
public String uploadFile(MultipartFile file) throws Exception
{
InputStream inputStream = file.getInputStream();
StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(),
FileTypeUtils.getExtension(file), null);
IoUtils.closeQuietly(inputStream);
InputStream inputStream = null;
try
{
inputStream = file.getInputStream();
StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(), FileTypeUtils.getExtension(file), null);
return domain + "/" + storePath.getFullPath();
}
catch (Exception e)
{
throw new RuntimeException("FastDfs Failed to upload file", e);
}
finally
{
IoUtils.closeQuietly(inputStream);
}
}
}

@ -33,9 +33,12 @@ public class MinioSysFileServiceImpl implements ISysFileService
*/
@Override
public String uploadFile(MultipartFile file) throws Exception
{
InputStream inputStream = null;
try
{
String fileName = FileUploadUtils.extractFilename(file);
InputStream inputStream = file.getInputStream();
inputStream = file.getInputStream();
PutObjectArgs args = PutObjectArgs.builder()
.bucket(minioConfig.getBucketName())
.object(fileName)
@ -43,7 +46,15 @@ public class MinioSysFileServiceImpl implements ISysFileService
.contentType(file.getContentType())
.build();
client.putObject(args);
IoUtils.closeQuietly(inputStream);
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
}
catch (Exception e)
{
throw new RuntimeException("Minio Failed to upload file", e);
}
finally
{
IoUtils.closeQuietly(inputStream);
}
}
}

Loading…
Cancel
Save