Skip to content

Commit

Permalink
🐛 image type judge
Browse files Browse the repository at this point in the history
  • Loading branch information
dongm2ez committed Aug 14, 2018
1 parent a1f85e4 commit 4dff10c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/com/tale/controller/admin/IndexController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import lombok.extern.slf4j.Slf4j;

import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -93,14 +94,18 @@ public RestResponse<?> upload(Request request) {
if ((fileItem.getLength() / 1024) <= TaleConst.MAX_FILE_SIZE) {
String fkey = TaleUtils.getFileKey(fname);

String ftype = fileItem.getContentType().contains("image") ? Types.IMAGE : Types.FILE;
String filePath = TaleUtils.UP_DIR + fkey;
String newFileName = TaleUtils.getFileName(fkey);
String thumbnailFilePath = TaleUtils.UP_DIR + fkey.replace(newFileName, "thumbnail_" + newFileName);
String ftype = fileItem.getContentType().contains("image") ? Types.IMAGE : Types.FILE;
String filePath = TaleUtils.UP_DIR + fkey;


try {
Files.write(Paths.get(filePath), fileItem.getData());
ImageUtils.cutCenterImage(CLASSPATH + fkey, thumbnailFilePath, 270, 380);
if (TaleUtils.isImage(new File(filePath))) {
String newFileName = TaleUtils.getFileName(fkey);
String thumbnailFilePath = TaleUtils.UP_DIR + fkey.replace(newFileName, "thumbnail_" + newFileName);
ImageUtils.cutCenterImage(CLASSPATH + fkey, thumbnailFilePath, 270, 380);

}
} catch (IOException e) {
log.error("", e);
}
Expand Down

0 comments on commit 4dff10c

Please sign in to comment.