优化文件异常输入流未关闭的问题
This commit is contained in:
parent
2335157f6e
commit
92c6d21855
@ -37,10 +37,20 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
|
|||||||
@Override
|
@Override
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
public String uploadFile(MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
InputStream inputStream = file.getInputStream();
|
InputStream inputStream = null;
|
||||||
StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(),
|
try
|
||||||
FileTypeUtils.getExtension(file), null);
|
{
|
||||||
IoUtils.closeQuietly(inputStream);
|
inputStream = file.getInputStream();
|
||||||
|
StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(), FileTypeUtils.getExtension(file), null);
|
||||||
return domain + "/" + storePath.getFullPath();
|
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
|
@Override
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
public String uploadFile(MultipartFile file) throws Exception
|
||||||
|
{
|
||||||
|
InputStream inputStream = null;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
String fileName = FileUploadUtils.extractFilename(file);
|
String fileName = FileUploadUtils.extractFilename(file);
|
||||||
InputStream inputStream = file.getInputStream();
|
inputStream = file.getInputStream();
|
||||||
PutObjectArgs args = PutObjectArgs.builder()
|
PutObjectArgs args = PutObjectArgs.builder()
|
||||||
.bucket(minioConfig.getBucketName())
|
.bucket(minioConfig.getBucketName())
|
||||||
.object(fileName)
|
.object(fileName)
|
||||||
@ -43,7 +46,15 @@ public class MinioSysFileServiceImpl implements ISysFileService
|
|||||||
.contentType(file.getContentType())
|
.contentType(file.getContentType())
|
||||||
.build();
|
.build();
|
||||||
client.putObject(args);
|
client.putObject(args);
|
||||||
IoUtils.closeQuietly(inputStream);
|
|
||||||
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
|
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Minio Failed to upload file", e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IoUtils.closeQuietly(inputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user