fix(创建文件): 自定义本地路径,创建文件失败
This commit is contained in:
parent
0b1d3d3e22
commit
5fd3c4f6ff
@ -230,13 +230,8 @@ public class FiletransferController {
|
|||||||
|
|
||||||
httpServletResponse.addHeader("Content-Disposition", "fileName=" + fileName);// 设置文件名
|
httpServletResponse.addHeader("Content-Disposition", "fileName=" + fileName);// 设置文件名
|
||||||
|
|
||||||
try {
|
filetransferService.previewFile(httpServletResponse, previewDTO);
|
||||||
filetransferService.previewFile(httpServletResponse, previewDTO);
|
|
||||||
}catch (Exception e){
|
|
||||||
//org.apache.catalina.connector.ClientAbortException: java.io.IOException: 你的主机中的软件中止了一个已建立的连接。
|
|
||||||
e.printStackTrace();
|
|
||||||
log.error("该异常忽略不做处理:" + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.qiwenshare.file.controller;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
||||||
import com.qiwenshare.common.exception.NotLoginException;
|
import com.qiwenshare.common.exception.NotLoginException;
|
||||||
import com.qiwenshare.common.result.RestResult;
|
import com.qiwenshare.common.result.RestResult;
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
@ -89,8 +90,8 @@ public class OfficeController {
|
|||||||
} else if ("pptx".equals(extendName)) {
|
} else if ("pptx".equals(extendName)) {
|
||||||
templateFilePath = "template/PowerPoint.pptx";
|
templateFilePath = "template/PowerPoint.pptx";
|
||||||
}
|
}
|
||||||
String templateFileUrl = UFOPUtils.getStaticPath() + templateFilePath;
|
String url2 = ClassUtils.getDefaultClassLoader().getResource("static/" + templateFilePath).getPath();
|
||||||
FileInputStream fileInputStream = new FileInputStream(templateFileUrl);
|
FileInputStream fileInputStream = new FileInputStream(url2);
|
||||||
Copier copier = ufopFactory.getCopier();
|
Copier copier = ufopFactory.getCopier();
|
||||||
CopyFile copyFile = new CopyFile();
|
CopyFile copyFile = new CopyFile();
|
||||||
copyFile.setExtendName(extendName);
|
copyFile.setExtendName(extendName);
|
||||||
|
@ -11,9 +11,4 @@ public class BatchDeleteFileDTO {
|
|||||||
@Schema(description="文件集合", required = true)
|
@Schema(description="文件集合", required = true)
|
||||||
private String files;
|
private String files;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
boolean ddd = Pattern.matches("(?!((^(con)$)|^(con)/..*|(^(prn)$)|^(prn)/..*|(^(aux)$)|^(aux)/..*|(^(nul)$)|^(nul)/..*|(^(com)[1-9]$)|^(com)[1-9]/..*|(^(lpt)[1-9]$)|^(lpt)[1-9]/..*)|^/s+|.*/s$)(^[^/////:/*/?/\"/</>/|]{1,255}$)", "con1");
|
|
||||||
System.out.println(ddd);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
@Schema(name = "下载文件DTO",required = true)
|
@Schema(name = "下载文件DTO",required = true)
|
||||||
public class DownloadFileDTO {
|
public class DownloadFileDTO {
|
||||||
private Long userFileId;
|
private long userFileId;
|
||||||
private String token;
|
private String token;
|
||||||
@Schema(description="批次号")
|
@Schema(description="批次号")
|
||||||
private String shareBatchNum;
|
private String shareBatchNum;
|
||||||
|
@ -250,18 +250,29 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Downloader downloader = ufopFactory.getDownloader(StorageTypeEnum.LOCAL.getCode());
|
String zipPath = "";
|
||||||
DownloadFile downloadFile = new DownloadFile();
|
try {
|
||||||
downloadFile.setFileUrl("temp" + File.separator+userFile.getFileName() + ".zip");
|
Downloader downloader = ufopFactory.getDownloader(StorageTypeEnum.LOCAL.getCode());
|
||||||
File tempFile = new File(UFOPUtils.getStaticPath() + downloadFile.getFileUrl());
|
DownloadFile downloadFile = new DownloadFile();
|
||||||
httpServletResponse.setContentLengthLong(tempFile.length());
|
downloadFile.setFileUrl("temp" + File.separator + userFile.getFileName() + ".zip");
|
||||||
downloader.download(httpServletResponse, downloadFile);
|
File tempFile = new File(UFOPUtils.getStaticPath() + downloadFile.getFileUrl());
|
||||||
String zipPath = UFOPUtils.getStaticPath() + "temp" + File.separator+userFile.getFileName() + ".zip";
|
httpServletResponse.setContentLengthLong(tempFile.length());
|
||||||
File file = new File(zipPath);
|
downloader.download(httpServletResponse, downloadFile);
|
||||||
if (file.exists()) {
|
zipPath = UFOPUtils.getStaticPath() + "temp" + File.separator + userFile.getFileName() + ".zip";
|
||||||
file.delete();
|
} catch (Exception e) {
|
||||||
}
|
//org.apache.catalina.connector.ClientAbortException: java.io.IOException: Connection reset by peer
|
||||||
|
if (e.getMessage().contains("ClientAbortException")) {
|
||||||
|
//该异常忽略不做处理
|
||||||
|
} else {
|
||||||
|
log.error("下传zip文件出现异常:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
File file = new File(zipPath);
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,14 +288,24 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
PreviewFile previewFile = new PreviewFile();
|
PreviewFile previewFile = new PreviewFile();
|
||||||
previewFile.setFileUrl(fileBean.getFileUrl());
|
previewFile.setFileUrl(fileBean.getFileUrl());
|
||||||
previewFile.setFileSize(fileBean.getFileSize());
|
previewFile.setFileSize(fileBean.getFileSize());
|
||||||
if ("true".equals(previewDTO.getIsMin())) {
|
try {
|
||||||
previewer.imageThumbnailPreview(httpServletResponse, previewFile);
|
if ("true".equals(previewDTO.getIsMin())) {
|
||||||
|
previewer.imageThumbnailPreview(httpServletResponse, previewFile);
|
||||||
|
} else {
|
||||||
|
previewer.imageOriginalPreview(httpServletResponse, previewFile);
|
||||||
|
}
|
||||||
|
} catch (Exception e){
|
||||||
|
//org.apache.catalina.connector.ClientAbortException: java.io.IOException: 你的主机中的软件中止了一个已建立的连接。
|
||||||
|
if (e.getMessage().contains("ClientAbortException")) {
|
||||||
|
//该异常忽略不做处理
|
||||||
} else {
|
} else {
|
||||||
previewer.imageOriginalPreview(httpServletResponse, previewFile);
|
log.error("预览文件出现异常:{}", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteFile(FileBean fileBean) {
|
public void deleteFile(FileBean fileBean) {
|
||||||
Deleter deleter = null;
|
Deleter deleter = null;
|
||||||
@ -292,7 +313,6 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
deleter = ufopFactory.getDeleter(fileBean.getStorageType());
|
deleter = ufopFactory.getDeleter(fileBean.getStorageType());
|
||||||
DeleteFile deleteFile = new DeleteFile();
|
DeleteFile deleteFile = new DeleteFile();
|
||||||
deleteFile.setFileUrl(fileBean.getFileUrl());
|
deleteFile.setFileUrl(fileBean.getFileUrl());
|
||||||
// deleteFile.setTimeStampName(fileBean.getTimeStampName());
|
|
||||||
deleter.delete(deleteFile);
|
deleter.delete(deleteFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class UserService extends ServiceImpl<UserMapper, UserBean> implements IU
|
|||||||
try {
|
try {
|
||||||
c = JjwtUtil.parseJWT(token);
|
c = JjwtUtil.parseJWT(token);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("解码异常:" + e);
|
log.info("解码异常:" + e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user