From e158ed345f92054dcc941af6db1b193df6490ead Mon Sep 17 00:00:00 2001 From: PeterAlbus Date: Sun, 2 Jan 2022 13:11:10 +0800 Subject: [PATCH] add api of upload origin image --- .../controller/PhotoController.java | 25 +++++++++++++++++++ .../com/peteralbus/service/PhotoService.java | 19 ++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/peteralbus/controller/PhotoController.java b/src/main/java/com/peteralbus/controller/PhotoController.java index a4e7fa7..7c17e30 100644 --- a/src/main/java/com/peteralbus/controller/PhotoController.java +++ b/src/main/java/com/peteralbus/controller/PhotoController.java @@ -97,4 +97,29 @@ public class PhotoController return "error:"+e.getMessage(); } } + + /** + * Custom upload string. + * + * @param file the file + * @param path the path + * @return the string + */ + @PostMapping("/uploadOriginImg") + public String uploadOriginImg(@RequestParam("file") MultipartFile file,String path) + { + /*pathExample:blog/imgs/photo/*/ + String uploadPath="/home/PeterAlbus/assets/"+path; + // 获取上传的文件名称 + String fileName = file.getOriginalFilename(); + File dest = new File(uploadPath + fileName); + try { + // 上传的文件被保存了 + file.transferTo(dest); + return "https://www.peteralbus.com:8440/assets/"+path+fileName; + } catch (IOException e) { + e.printStackTrace(); + return "error:"+e.getMessage(); + } + } } diff --git a/src/main/java/com/peteralbus/service/PhotoService.java b/src/main/java/com/peteralbus/service/PhotoService.java index c9777a8..0a591b7 100644 --- a/src/main/java/com/peteralbus/service/PhotoService.java +++ b/src/main/java/com/peteralbus/service/PhotoService.java @@ -4,10 +4,25 @@ import com.peteralbus.domain.Photo; import java.util.List; -/*Created on 2021/7/29.*/ -/*@author PeterAlbus*/ + +/** + * The interface Photo service. + * @author PeterAlbus + */ public interface PhotoService { + /** + * Query all list. + * + * @return the list + */ List queryAll(); + + /** + * Add int. + * + * @param photo the photo + * @return the int + */ int add(Photo photo); }