|
|
@@ -1,5 +1,8 @@
|
|
|
package com.style24.front.biz.web;
|
|
|
|
|
|
+import java.awt.Image;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
@@ -22,6 +25,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
+import com.drew.imaging.ImageMetadataReader;
|
|
|
+import com.drew.imaging.ImageProcessingException;
|
|
|
+import com.drew.metadata.Directory;
|
|
|
+import com.drew.metadata.Metadata;
|
|
|
+import com.drew.metadata.MetadataException;
|
|
|
+import com.drew.metadata.exif.ExifIFD0Directory;
|
|
|
import com.gagaframework.web.util.GagaFileUploadUtil;
|
|
|
import com.gagaframework.web.util.GagaFileUtil;
|
|
|
import com.gagaframework.web.util.GagaUploadedFileInfo;
|
|
|
@@ -94,15 +103,24 @@ public class TsfCommonController extends TsfBaseController {
|
|
|
* @return 업로드한 파일의 정보
|
|
|
* @throws IOException
|
|
|
* @author gagamel
|
|
|
+ * @throws ImageProcessingException
|
|
|
+ * @throws MetadataException
|
|
|
* @since 2019. 12. 6
|
|
|
*/
|
|
|
@PostMapping("/file/upload")
|
|
|
@ResponseBody
|
|
|
- public GagaUploadedFileInfo uploadFile(@RequestParam(value = "subDir") String subDir, @RequestParam(value = "policy", required = false) String policy, MultipartFile file) throws IOException {
|
|
|
+ public GagaUploadedFileInfo uploadFile(@RequestParam(value = "subDir") String subDir, @RequestParam(value = "policy", required = false) String policy, MultipartFile file) throws IOException, ImageProcessingException, MetadataException {
|
|
|
if (StringUtils.isEmpty(policy)) {
|
|
|
policy = "default";
|
|
|
}
|
|
|
-
|
|
|
+ int orientation = 1;
|
|
|
+ Metadata metadata = ImageMetadataReader.readMetadata(convert(file));
|
|
|
+
|
|
|
+ Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
|
|
|
+ if(directory != null) {
|
|
|
+ orientation = directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
|
|
|
+ }
|
|
|
+ log.debug("orientation: {}", orientation);
|
|
|
String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload." + policy + ".target.path"), subDir);
|
|
|
|
|
|
GagaFileUploadUtil fuUtil = new GagaFileUploadUtil(targetPath, Long.parseLong(env.getProperty("upload." + policy + ".max.size")), env.getProperty("upload." + policy + ".allow.extension"), env.getProperty("upload." + policy + ".view"));
|
|
|
@@ -121,6 +139,17 @@ public class TsfCommonController extends TsfBaseController {
|
|
|
// }
|
|
|
return ufInfo;
|
|
|
}
|
|
|
+
|
|
|
+ public File convert(MultipartFile multipartFile) throws IOException {
|
|
|
+ File file = new File(multipartFile.getOriginalFilename());
|
|
|
+ file.createNewFile();
|
|
|
+ FileOutputStream fos = new FileOutputStream(file);
|
|
|
+ fos.write(multipartFile.getBytes());
|
|
|
+ fos.close();
|
|
|
+ return file;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Delete a file
|