Browse Source

fix[litemall-admin-api, litemall-core]: 对象存储返回对象存储信息,而不仅仅是图片链接

Junling Bu 6 years ago
parent
commit
fd80760bb5

+ 2 - 4
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminStorageController.java

@@ -56,10 +56,8 @@ public class AdminStorageController {
     @PostMapping("/create")
     public Object create(@RequestParam("file") MultipartFile file) throws IOException {
         String originalFilename = file.getOriginalFilename();
-        String url = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename);
-        Map<String, Object> data = new HashMap<>();
-        data.put("url", url);
-        return ResponseUtil.ok(data);
+        LitemallStorage litemallStorage = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename);
+        return ResponseUtil.ok(litemallStorage);
     }
 
     @RequiresPermissions("admin:storage:read")

+ 5 - 4
litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeService.java

@@ -5,6 +5,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
 import org.linlinjava.litemall.core.storage.StorageService;
 import org.linlinjava.litemall.core.system.SystemConfig;
 import org.linlinjava.litemall.db.domain.LitemallGroupon;
+import org.linlinjava.litemall.db.domain.LitemallStorage;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
@@ -33,9 +34,9 @@ public class QCodeService {
             byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
             ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData);
             //存储分享图
-            String url = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(groupon.getId().toString()));
+            LitemallStorage storageInfo = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(groupon.getId().toString()));
 
-            return url;
+            return storageInfo.getUrl();
         } catch (WxErrorException e) {
             e.printStackTrace();
         } catch (FileNotFoundException e) {
@@ -67,9 +68,9 @@ public class QCodeService {
             byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
             ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData);
             //存储分享图
-            String url = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(goodId));
+            LitemallStorage litemallStorage = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(goodId));
 
-            return url;
+            return litemallStorage.getUrl();
         } catch (WxErrorException e) {
             e.printStackTrace();
         } catch (FileNotFoundException e) {

+ 2 - 2
litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java

@@ -43,7 +43,7 @@ public class StorageService {
      * @param contentType   文件类型
      * @param fileName      文件索引名
      */
-    public String store(InputStream inputStream, long contentLength, String contentType, String fileName) {
+    public LitemallStorage store(InputStream inputStream, long contentLength, String contentType, String fileName) {
         String key = generateKey(fileName);
         storage.store(inputStream, contentLength, contentType, key);
 
@@ -56,7 +56,7 @@ public class StorageService {
         storageInfo.setUrl(url);
         litemallStorageService.add(storageInfo);
 
-        return url;
+        return storageInfo;
     }
 
     private String generateKey(String originalFilename) {

+ 2 - 5
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java

@@ -53,11 +53,8 @@ public class WxStorageController {
     @PostMapping("/upload")
     public Object upload(@RequestParam("file") MultipartFile file) throws IOException {
         String originalFilename = file.getOriginalFilename();
-        String url = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename);
-
-        Map<String, Object> data = new HashMap<>();
-        data.put("url", url);
-        return ResponseUtil.ok(data);
+        LitemallStorage litemallStorage = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename);
+        return ResponseUtil.ok(litemallStorage);
     }
 
     /**