commit
b6aa1ddbde
@ -143,7 +143,13 @@ public class FiletransferController {
|
|||||||
public void downloadFile(HttpServletResponse httpServletResponse, DownloadFileDTO downloadFileDTO) {
|
public void downloadFile(HttpServletResponse httpServletResponse, DownloadFileDTO downloadFileDTO) {
|
||||||
httpServletResponse.setContentType("application/force-download");// 设置强制下载不打开
|
httpServletResponse.setContentType("application/force-download");// 设置强制下载不打开
|
||||||
UserFile userFile = userFileService.getById(downloadFileDTO.getUserFileId());
|
UserFile userFile = userFileService.getById(downloadFileDTO.getUserFileId());
|
||||||
String fileName = userFile.getFileName() + "." + userFile.getExtendName();
|
String fileName = "";
|
||||||
|
if (userFile.getIsDir() == 1) {
|
||||||
|
fileName = userFile.getFileName() + ".zip";
|
||||||
|
} else {
|
||||||
|
fileName = userFile.getFileName() + "." + userFile.getExtendName();
|
||||||
|
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");
|
fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
@ -137,8 +137,6 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
|
|
||||||
if (userFile.getIsDir() == 0) {
|
if (userFile.getIsDir() == 0) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FileBean fileBean = fileMapper.selectById(userFile.getFileId());
|
FileBean fileBean = fileMapper.selectById(userFile.getFileId());
|
||||||
Downloader downloader = null;
|
Downloader downloader = null;
|
||||||
if (fileBean.getIsOSS() != null && fileBean.getIsOSS() == 1) {
|
if (fileBean.getIsOSS() != null && fileBean.getIsOSS() == 1) {
|
||||||
@ -154,13 +152,12 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
log.error("下载失败,文件存储类型不支持下载,storageType:{}, isOSS:{}", fileBean.getStorageType(), fileBean.getIsOSS());
|
log.error("下载失败,文件存储类型不支持下载,storageType:{}, isOSS:{}", fileBean.getStorageType(), fileBean.getIsOSS());
|
||||||
throw new UploadGeneralException("下载失败");
|
throw new UploadGeneralException("下载失败");
|
||||||
}
|
}
|
||||||
DownloadFile uploadFile = new DownloadFile();
|
DownloadFile downloadFile = new DownloadFile();
|
||||||
uploadFile.setFileUrl(fileBean.getFileUrl());
|
downloadFile.setFileUrl(fileBean.getFileUrl());
|
||||||
// uploadFile.setTimeStampName(fileBean.getTimeStampName());
|
downloader.download(httpServletResponse, downloadFile);
|
||||||
downloader.download(httpServletResponse, uploadFile);
|
|
||||||
} else {
|
} else {
|
||||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
lambdaQueryWrapper.likeRight(UserFile::getFilePath, userFile.getFilePath())
|
lambdaQueryWrapper.likeRight(UserFile::getFilePath, userFile.getFilePath() + userFile.getFileName() + "/")
|
||||||
.eq(UserFile::getUserId, userFile.getUserId())
|
.eq(UserFile::getUserId, userFile.getUserId())
|
||||||
.eq(UserFile::getIsDir, 0)
|
.eq(UserFile::getIsDir, 0)
|
||||||
.eq(UserFile::getDeleteFlag, 0);
|
.eq(UserFile::getDeleteFlag, 0);
|
||||||
@ -183,52 +180,68 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
ZipOutputStream zos = new ZipOutputStream(csum);
|
ZipOutputStream zos = new ZipOutputStream(csum);
|
||||||
BufferedOutputStream out = new BufferedOutputStream(zos);
|
BufferedOutputStream out = new BufferedOutputStream(zos);
|
||||||
|
|
||||||
zos.setComment("A test of Java Zipping");
|
// zos.setComment("");
|
||||||
for (UserFile userFile1 : userFileList) {
|
try {
|
||||||
FileBean fileBean = fileMapper.selectById(userFile.getFileId());
|
for (UserFile userFile1 : userFileList) {
|
||||||
Downloader downloader = null;
|
FileBean fileBean = fileMapper.selectById(userFile1.getFileId());
|
||||||
if (fileBean.getIsOSS() != null && fileBean.getIsOSS() == 1) {
|
Downloader downloader = null;
|
||||||
downloader = aliyunOSSOperationFactory.getDownloader();
|
if (fileBean.getIsOSS() != null && fileBean.getIsOSS() == 1) {
|
||||||
} else if (fileBean.getStorageType() == 0) {
|
downloader = aliyunOSSOperationFactory.getDownloader();
|
||||||
downloader = localStorageOperationFactory.getDownloader();
|
} else if (fileBean.getStorageType() == 0) {
|
||||||
} else if (fileBean.getStorageType() == 1) {
|
downloader = localStorageOperationFactory.getDownloader();
|
||||||
downloader = aliyunOSSOperationFactory.getDownloader();
|
} else if (fileBean.getStorageType() == 1) {
|
||||||
} else if (fileBean.getStorageType() == 2) {
|
downloader = aliyunOSSOperationFactory.getDownloader();
|
||||||
downloader = fastDFSOperationFactory.getDownloader();
|
} else if (fileBean.getStorageType() == 2) {
|
||||||
}
|
downloader = fastDFSOperationFactory.getDownloader();
|
||||||
if (downloader == null) {
|
|
||||||
log.error("下载失败,文件存储类型不支持下载,storageType:{}, isOSS:{}", fileBean.getStorageType(), fileBean.getIsOSS());
|
|
||||||
throw new UploadGeneralException("下载失败");
|
|
||||||
}
|
|
||||||
DownloadFile downloadFile = new DownloadFile();
|
|
||||||
downloadFile.setFileUrl(fileBean.getFileUrl());
|
|
||||||
InputStream inputStream = downloader.getInputStream(downloadFile);
|
|
||||||
BufferedInputStream bis = new BufferedInputStream(inputStream);
|
|
||||||
try {
|
|
||||||
zos.putNextEntry(new ZipEntry(userFile1.getFilePath()));
|
|
||||||
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int i = bis.read(buffer);
|
|
||||||
while (i != -1) {
|
|
||||||
out.write(buffer, 0, i);
|
|
||||||
i = bis.read(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (downloader == null) {
|
||||||
|
log.error("下载失败,文件存储类型不支持下载,storageType:{}, isOSS:{}", fileBean.getStorageType(), fileBean.getIsOSS());
|
||||||
|
throw new UploadGeneralException("下载失败");
|
||||||
|
}
|
||||||
|
DownloadFile downloadFile = new DownloadFile();
|
||||||
|
downloadFile.setFileUrl(fileBean.getFileUrl());
|
||||||
|
InputStream inputStream = downloader.getInputStream(downloadFile);
|
||||||
|
BufferedInputStream bis = new BufferedInputStream(inputStream);
|
||||||
|
try {
|
||||||
|
zos.putNextEntry(new ZipEntry(userFile1.getFilePath().replace(userFile.getFilePath(), "/") + userFile1.getFileName() + "." + userFile1.getExtendName()));
|
||||||
|
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int i = bis.read(buffer);
|
||||||
|
while (i != -1) {
|
||||||
|
out.write(buffer, 0, i);
|
||||||
|
i = bis.read(buffer);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("" + e);
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
bis.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
out.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("压缩过程中出现异常:"+ e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
|
|
||||||
try {
|
|
||||||
bis.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
out.flush();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Downloader downloader = localStorageOperationFactory.getDownloader();
|
||||||
|
DownloadFile downloadFile = new DownloadFile();
|
||||||
|
downloadFile.setFileUrl("temp" + File.separator+userFile.getFileName() + ".zip");
|
||||||
|
downloader.download(httpServletResponse, downloadFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user