Search in sources :

Example 1 with PreviewFile

use of com.qiwenshare.ufop.operation.preview.domain.PreviewFile 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());
        }
    }
}
Also used : Previewer(com.qiwenshare.ufop.operation.preview.Previewer) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) UploadException(com.qiwenshare.ufop.exception.operation.UploadException) PreviewFile(com.qiwenshare.ufop.operation.preview.domain.PreviewFile) UploadException(com.qiwenshare.ufop.exception.operation.UploadException) DownloadException(com.qiwenshare.ufop.exception.operation.DownloadException)

Example 2 with PreviewFile

use of com.qiwenshare.ufop.operation.preview.domain.PreviewFile 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());
        }
    }
}
Also used : Previewer(com.qiwenshare.ufop.operation.preview.Previewer) UploadException(com.qiwenshare.ufop.exception.operation.UploadException) PreviewFile(com.qiwenshare.ufop.operation.preview.domain.PreviewFile) UploadException(com.qiwenshare.ufop.exception.operation.UploadException) DownloadException(com.qiwenshare.ufop.exception.operation.DownloadException)

Aggregations

DownloadException (com.qiwenshare.ufop.exception.operation.DownloadException)2 UploadException (com.qiwenshare.ufop.exception.operation.UploadException)2 Previewer (com.qiwenshare.ufop.operation.preview.Previewer)2 PreviewFile (com.qiwenshare.ufop.operation.preview.domain.PreviewFile)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1