use of com.qiwenshare.ufop.operation.preview.Previewer in project qiwen-file by qiwenshare.
the class FiletransferService method previewPictureFile.
@Override
public void previewPictureFile(HttpServletResponse httpServletResponse, PreviewDTO previewDTO) {
byte[] bytesUrl = Base64.getDecoder().decode(previewDTO.getUrl());
PictureFile pictureFile = new PictureFile();
pictureFile.setFileUrl(new String(bytesUrl));
pictureFile = pictureFileMapper.selectOne(new QueryWrapper<>(pictureFile));
Previewer previewer = ufopFactory.getPreviewer(pictureFile.getStorageType());
if (previewer == null) {
log.error("预览失败,文件存储类型不支持预览,storageType:{}", pictureFile.getStorageType());
throw new UploadException("预览失败");
}
PreviewFile previewFile = new PreviewFile();
previewFile.setFileUrl(pictureFile.getFileUrl());
// previewFile.setFileSize(pictureFile.getFileSize());
try {
String mime = MimeUtils.getMime(pictureFile.getExtendName());
httpServletResponse.setHeader("Content-Type", mime);
String fileName = pictureFile.getFileName() + "." + pictureFile.getExtendName();
try {
fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// 设置文件名
httpServletResponse.addHeader("Content-Disposition", "fileName=" + fileName);
previewer.imageOriginalPreview(httpServletResponse, previewFile);
} catch (Exception e) {
// org.apache.catalina.connector.ClientAbortException: java.io.IOException: 你的主机中的软件中止了一个已建立的连接。
if (e.getMessage().contains("ClientAbortException")) {
// 该异常忽略不做处理
} else {
log.error("预览文件出现异常:{}", e.getMessage());
}
}
}
use of com.qiwenshare.ufop.operation.preview.Previewer in project qiwen-file by qiwenshare.
the class FiletransferService method previewFile.
@Override
public void previewFile(HttpServletResponse httpServletResponse, PreviewDTO previewDTO) {
UserFile userFile = userFileMapper.selectById(previewDTO.getUserFileId());
FileBean fileBean = fileMapper.selectById(userFile.getFileId());
Previewer previewer = ufopFactory.getPreviewer(fileBean.getStorageType());
if (previewer == null) {
log.error("预览失败,文件存储类型不支持预览,storageType:{}", fileBean.getStorageType());
throw new UploadException("预览失败");
}
PreviewFile previewFile = new PreviewFile();
previewFile.setFileUrl(fileBean.getFileUrl());
try {
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 {
log.error("预览文件出现异常:{}", e.getMessage());
}
}
}
Aggregations