|
@@ -61,8 +61,11 @@ public class FileServiceImpl implements IFileService {
|
|
|
@Override
|
|
|
public List<UploadResult> upload(MultipartFile[] files, boolean parse) {
|
|
|
List<UploadResult> urls = new ArrayList<>(files.length);
|
|
|
+ //获取的当前时间
|
|
|
String timeFormat = FileUtils.getTimeFileDir();
|
|
|
+ //获取配置文件中图片文件预览路径
|
|
|
String url = ruoYiConfig.getUrl();
|
|
|
+ //获取配置文件中图片文件存储路径
|
|
|
String profile = RuoYiConfig.getProfile();
|
|
|
for (MultipartFile file : files) {
|
|
|
String fileHash = FileHashUtil.getFileHash(file);
|
|
@@ -79,12 +82,12 @@ public class FileServiceImpl implements IFileService {
|
|
|
}
|
|
|
urls.add(UploadResult.builder()
|
|
|
.url(url + hashFile.getUrl())
|
|
|
+ .path(hashFile.getPath())
|
|
|
.fileId(hashFile.getId())
|
|
|
.img(hashFile.getImage() == 1)
|
|
|
.fileSize(hashFile.getSize())
|
|
|
.detail(imgDetailInfo)
|
|
|
.build());
|
|
|
-
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -97,17 +100,16 @@ public class FileServiceImpl implements IFileService {
|
|
|
try {
|
|
|
//组合File.separator = \
|
|
|
File saveFile = new File(profile + File.separator + pathname);
|
|
|
- File saveFileThumbnail = new File(profile + File.separator + thumbnailPath);
|
|
|
//检查目录是否存在
|
|
|
FileUtils.checkOrCreateParentDir(saveFile);
|
|
|
file.transferTo(saveFile);
|
|
|
-
|
|
|
- //生成缩略图返回缩略图地址
|
|
|
- Thumbnails.of(saveFile)
|
|
|
- .size(120, 120)
|
|
|
- .toFile(saveFileThumbnail);
|
|
|
- // 如果图片需要立即解析属性信息,就同步操作去执行
|
|
|
if (parse) {
|
|
|
+ //生成缩略图返回缩略图地址
|
|
|
+ File saveFileThumbnail = new File(profile + File.separator + thumbnailPath);
|
|
|
+ Thumbnails.of(saveFile)
|
|
|
+ .size(120, 120)
|
|
|
+ .toFile(saveFileThumbnail);
|
|
|
+ // 如果图片需要立即解析属性信息,就同步操作去执行
|
|
|
imgDetailInfo = printImageTags(saveFile);
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
@@ -125,8 +127,10 @@ public class FileServiceImpl implements IFileService {
|
|
|
xmFile.setSize(file.getSize());
|
|
|
xmFile.setUrl("?path=" + URLEncoder.createDefault().encode(pathname, Charset.defaultCharset()));
|
|
|
xmFile.setDetail(JSON.toJSONString(imgDetailInfo));
|
|
|
- xmFile.setThumbnailPath(thumbnailPath);
|
|
|
- xmFile.setThumbnailUrl("?path=" + URLEncoder.createDefault().encode(thumbnailPath, Charset.defaultCharset()));
|
|
|
+ if(parse){
|
|
|
+ xmFile.setThumbnailPath(thumbnailPath);
|
|
|
+ xmFile.setThumbnailUrl("?path=" + URLEncoder.createDefault().encode(thumbnailPath, Charset.defaultCharset()));
|
|
|
+ }
|
|
|
zbFileService.save(xmFile);
|
|
|
// 如果图片需要立即解析属性信息
|
|
|
if (!parse && isImg(name)) {
|
|
@@ -136,6 +140,7 @@ public class FileServiceImpl implements IFileService {
|
|
|
|
|
|
urls.add(UploadResult.builder()
|
|
|
.url(url + xmFile.getUrl())
|
|
|
+ .path(pathname)
|
|
|
.fileId(xmFile.getId())
|
|
|
.img(xmFile.getImage() == 1)
|
|
|
.fileSize(xmFile.getSize())
|
|
@@ -148,6 +153,8 @@ public class FileServiceImpl implements IFileService {
|
|
|
@Override
|
|
|
public UploadResult upload(File file) {
|
|
|
String url = ruoYiConfig.getUrl();
|
|
|
+ //获取配置文件中图片文件存储路径
|
|
|
+ String profile = RuoYiConfig.getProfile();
|
|
|
String fileHash = FileHashUtil.getFileHash(file);
|
|
|
// 表示文件存在过了
|
|
|
ZbFile hashFile = zbFileService.findByHash(fileHash);
|
|
@@ -179,6 +186,7 @@ public class FileServiceImpl implements IFileService {
|
|
|
zbFileService.save(xmFile);
|
|
|
return UploadResult.builder()
|
|
|
.url(url + xmFile.getUrl())
|
|
|
+ .path(profile + File.separator + pathname)
|
|
|
.fileId(xmFile.getId())
|
|
|
.img(xmFile.getImage() == 1)
|
|
|
.fileSize(xmFile.getSize())
|
|
@@ -186,6 +194,7 @@ public class FileServiceImpl implements IFileService {
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
+ //监听解析图片路径
|
|
|
@Override
|
|
|
public ImgDetailInfo parseImgInfo(ZbFile zbFile) {
|
|
|
String path = RuoYiConfig.getProfile() + File.separator + zbFile.getPath();
|