use of com.github.lybgeek.upload.dto.FileUploadDTO in project springboot-learning by lyb-geek.
the class FileServiceImpl method sliceUpload.
@Override
public FileUploadDTO sliceUpload(FileUploadRequestDTO fileUploadRequestDTO) {
try {
completionService.submit(new FileCallable(UploadModeEnum.RANDOM_ACCESS, fileUploadRequestDTO));
FileUploadDTO fileUploadDTO = completionService.take().get();
return fileUploadDTO;
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
throw new BizException(e.getMessage(), 406);
} catch (ExecutionException e) {
log.error(e.getMessage(), e);
throw new BizException(e.getMessage(), 406);
}
}
use of com.github.lybgeek.upload.dto.FileUploadDTO in project springboot-learning by lyb-geek.
the class FileServiceImpl method checkFileMd5.
@Override
public FileUploadDTO checkFileMd5(FileUploadRequestDTO param) throws IOException {
Object uploadProgressObj = redisUtil.hget(FileConstant.FILE_UPLOAD_STATUS, param.getMd5());
if (uploadProgressObj == null) {
FileUploadDTO fileMd5DTO = FileUploadDTO.builder().code(FileCheckMd5Status.FILE_NO_UPLOAD.getValue()).build();
return fileMd5DTO;
}
String processingStr = uploadProgressObj.toString();
boolean processing = Boolean.parseBoolean(processingStr);
String value = String.valueOf(redisUtil.get(FileConstant.FILE_MD5_KEY + param.getMd5()));
return fillFileUploadDTO(param, processing, value);
}
use of com.github.lybgeek.upload.dto.FileUploadDTO in project springboot-learning by lyb-geek.
the class SliceUploadTemplate method renameFile.
/**
* 文件重命名
*
* @param toBeRenamed 将要修改名字的文件
* @param toFileNewName 新的名字
*/
private FileUploadDTO renameFile(File toBeRenamed, String toFileNewName) {
// 检查要重命名的文件是否存在,是否是文件
FileUploadDTO fileUploadDTO = new FileUploadDTO();
if (!toBeRenamed.exists() || toBeRenamed.isDirectory()) {
log.info("File does not exist: {}", toBeRenamed.getName());
fileUploadDTO.setUploadComplete(false);
return fileUploadDTO;
}
String ext = FileUtil.getExtension(toFileNewName);
String p = toBeRenamed.getParent();
String filePath = p + FileConstant.FILE_SEPARATORCHAR + toFileNewName;
File newFile = new File(filePath);
// 修改文件名
boolean uploadFlag = toBeRenamed.renameTo(newFile);
fileUploadDTO.setMtime(DateUtil.getCurrentTimeStamp());
fileUploadDTO.setUploadComplete(uploadFlag);
fileUploadDTO.setPath(filePath);
fileUploadDTO.setSize(newFile.length());
fileUploadDTO.setFileExt(ext);
fileUploadDTO.setFileId(toFileNewName);
return fileUploadDTO;
}
use of com.github.lybgeek.upload.dto.FileUploadDTO in project springboot-learning by lyb-geek.
the class FileController method upload.
@PostMapping(value = "/upload")
@ResponseBody
public Result<FileUploadDTO> upload(FileUploadRequestDTO fileUploadRequestDTO) throws IOException {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
FileUploadDTO fileUploadDTO = null;
if (isMultipart) {
StopWatch stopWatch = new StopWatch();
stopWatch.start("upload");
if (fileUploadRequestDTO.getChunk() != null && fileUploadRequestDTO.getChunks() > 0) {
fileUploadDTO = fileService.sliceUpload(fileUploadRequestDTO);
} else {
fileUploadDTO = fileService.upload(fileUploadRequestDTO);
}
stopWatch.stop();
log.info("{}", stopWatch.prettyPrint());
return new Result<FileUploadDTO>().setData(fileUploadDTO);
}
throw new BizException("上传失败", 406);
}
use of com.github.lybgeek.upload.dto.FileUploadDTO in project springboot-learning by lyb-geek.
the class FileController method checkFileMd5.
@RequestMapping(value = "checkFileMd5", method = RequestMethod.POST)
@ResponseBody
public Result<FileUploadDTO> checkFileMd5(String md5, String path) throws IOException {
FileUploadRequestDTO param = new FileUploadRequestDTO().setPath(path).setMd5(md5);
FileUploadDTO fileUploadDTO = fileService.checkFileMd5(param);
return new Result<FileUploadDTO>().setData(fileUploadDTO);
}
Aggregations