|
|
@@ -273,7 +273,7 @@ public class FileServiceImpl implements IFileService {
|
|
|
}
|
|
|
//生成缩略图
|
|
|
String tObjectKey = getThumbnailObjectKey(file.getName());
|
|
|
- putThumbnailImage(tObjectKey,file.getObjectKey());
|
|
|
+ putThumbnailImage(tObjectKey,file.getObjectKey(),true);
|
|
|
|
|
|
MediaFileEntity.MediaFileEntityBuilder builder = MediaFileEntity.builder();
|
|
|
|
|
|
@@ -368,8 +368,7 @@ public class FileServiceImpl implements IFileService {
|
|
|
}
|
|
|
MediaTypeEnum mediaTypeEnum = convertMediaType(entity);
|
|
|
String url = ossService.getObjectUrl(OssConfiguration.bucket, entity.getObjectKey()).toString();
|
|
|
-// String thumbnailURL = getThumbnailURL(entity);
|
|
|
- String thumbnailURL = null;
|
|
|
+ String thumbnailURL = getThumbnailURL(entity);
|
|
|
builder.fileName(entity.getFileName())
|
|
|
.fileId(entity.getFileId())
|
|
|
.filePath(entity.getFilePath())
|
|
|
@@ -416,28 +415,35 @@ public class FileServiceImpl implements IFileService {
|
|
|
String originFileName = entity.getFileName();
|
|
|
//缩略图路径
|
|
|
String tObjectKey = getThumbnailObjectKey(originFileName);
|
|
|
- putThumbnailImage(tObjectKey,entity.getObjectKey());
|
|
|
+ if(!putThumbnailImage(tObjectKey,entity.getObjectKey(),false)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
return ossService.getObjectUrl(OssConfiguration.bucket, tObjectKey).toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void putThumbnailImage(String tObjectKey, String originObjectKey) {
|
|
|
+ private boolean putThumbnailImage(String tObjectKey, String originObjectKey,boolean toCreate) {
|
|
|
if(originObjectKey.endsWith(PicExifUtil.MP4)) {
|
|
|
System.out.println(originObjectKey);
|
|
|
}
|
|
|
//生成缩略图
|
|
|
if(!ossService.objectExists(OssConfiguration.bucket,tObjectKey)) {
|
|
|
- BufferedImage bufferedImage = ThumbnailatorUtil.getThumbnail(originObjectKey,100,100);
|
|
|
- if(bufferedImage != null) {
|
|
|
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
- try {
|
|
|
- ImageIO.write(bufferedImage, JPEG, outputStream);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ if(toCreate) {
|
|
|
+ BufferedImage bufferedImage = ThumbnailatorUtil.getThumbnail(originObjectKey, 100, 100);
|
|
|
+ if (bufferedImage != null) {
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ try {
|
|
|
+ ImageIO.write(bufferedImage, JPEG, outputStream);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ ossService.putObject(OssConfiguration.bucket, tObjectKey, new ByteArrayInputStream(outputStream.toByteArray()));
|
|
|
}
|
|
|
- ossService.putObject(OssConfiguration.bucket,tObjectKey,new ByteArrayInputStream(outputStream.toByteArray()));
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
private String getThumbnailObjectKey(String originFileName) {
|