fix file download buffer
This commit is contained in:
@@ -19,9 +19,10 @@ public interface IFileStorage {
|
||||
* 下载
|
||||
* @param filePath
|
||||
* @param os
|
||||
* @param fileSize 文件大小
|
||||
* @author sr on 2022-03-01
|
||||
*/
|
||||
void download(String filePath, OutputStream os);
|
||||
void download(String filePath, OutputStream os, Long fileSize);
|
||||
|
||||
/**
|
||||
* @param filePath
|
||||
|
||||
@@ -103,7 +103,7 @@ public class FileServiceImpl implements FileService {
|
||||
String.format("attachment; filename=\"%1$s\"; filename*=utf-8''%1$s", encodFilename));
|
||||
}
|
||||
try (OutputStream outputStream = response.getOutputStream()) {
|
||||
fileStorage.download(fileRecord.getFilePath(), outputStream);
|
||||
fileStorage.download(fileRecord.getFilePath(), outputStream, fileRecord.getFileSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,10 +65,10 @@ public class AliFileStorage implements IFileStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(String filePath, OutputStream os) {
|
||||
public void download(String filePath, OutputStream os, Long fileSize) {
|
||||
try(InputStream is = download(filePath)) {
|
||||
try {
|
||||
IOUtils.copy(is, os);
|
||||
IOUtils.copy(is, os, fileSize != null ? fileSize.intValue() : 4096);
|
||||
} catch (ClientAbortException e) {
|
||||
log.warn("客户端主动断开连接: {}", e.getMessage());
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ public class LocalFileStorage implements IFileStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(String filePath, OutputStream os) {
|
||||
public void download(String filePath, OutputStream os, Long fileSize) {
|
||||
try (InputStream inputStream = download(filePath)) {
|
||||
IOUtils.copy(inputStream, os);
|
||||
IOUtils.copy(inputStream, os, fileSize != null ? fileSize.intValue() : 4096);
|
||||
} catch (IOException e) {
|
||||
log.info("下载异常", e);
|
||||
throw new BusinessException("下载异常" + e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user