use of com.dimple.project.tool.domain.LocalStorage in project DimpleBlog by martin-chips.
the class LocalStorageServiceImpl method upload.
@Override
public int upload(String name, MultipartFile multipartFile) {
// 检查大小
// 获取后缀
String suffix = FileUtils.getExtensionName(multipartFile.getOriginalFilename());
String type = FileUtils.getFileType(suffix);
File file = FileUtils.upload(multipartFile, DimpleBlogConfig.getProfile() + type + File.separator);
if (Objects.isNull(file)) {
throw new CustomException("上传失败");
}
// 防止异常出错
try {
name = StringUtils.isBlank(name) ? FileUtils.getFileNameNoExtension(multipartFile.getOriginalFilename()) : name;
LocalStorage localStorage = new LocalStorage(file.getName(), name, suffix, file.getPath(), type, FileUtils.getSizeString(multipartFile.getSize()));
localStorage.setCreateBy(SecurityUtils.getUsername());
return localStorageMapper.insertLocalStorage(localStorage);
} catch (Exception e) {
FileUtils.del(file);
throw e;
}
}
use of com.dimple.project.tool.domain.LocalStorage in project DimpleBlog by martin-chips.
the class LocalStorageServiceImpl method deleteLocalStorage.
@Override
public int deleteLocalStorage(Long id) {
String username = SecurityUtils.getUsername();
LocalStorage localStorage = localStorageMapper.selectLocalStorageById(id);
if (Objects.isNull(localStorage)) {
throw new CustomException("文件不存在");
}
// 删除文件
String path = localStorage.getPath();
FileUtils.del(path);
return localStorageMapper.deleteLocalStorageById(id, username);
}
Aggregations