Commit fd80760b authored by Junling Bu's avatar Junling Bu
Browse files

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

parent 520c9517
...@@ -56,10 +56,8 @@ public class AdminStorageController { ...@@ -56,10 +56,8 @@ public class AdminStorageController {
@PostMapping("/create") @PostMapping("/create")
public Object create(@RequestParam("file") MultipartFile file) throws IOException { public Object create(@RequestParam("file") MultipartFile file) throws IOException {
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
String url = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename); LitemallStorage litemallStorage = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename);
Map<String, Object> data = new HashMap<>(); return ResponseUtil.ok(litemallStorage);
data.put("url", url);
return ResponseUtil.ok(data);
} }
@RequiresPermissions("admin:storage:read") @RequiresPermissions("admin:storage:read")
......
...@@ -5,6 +5,7 @@ import me.chanjar.weixin.common.error.WxErrorException; ...@@ -5,6 +5,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
import org.linlinjava.litemall.core.storage.StorageService; import org.linlinjava.litemall.core.storage.StorageService;
import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.core.system.SystemConfig;
import org.linlinjava.litemall.db.domain.LitemallGroupon; import org.linlinjava.litemall.db.domain.LitemallGroupon;
import org.linlinjava.litemall.db.domain.LitemallStorage;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -33,9 +34,9 @@ public class QCodeService { ...@@ -33,9 +34,9 @@ public class QCodeService {
byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName); byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData); 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) { } catch (WxErrorException e) {
e.printStackTrace(); e.printStackTrace();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
...@@ -67,9 +68,9 @@ public class QCodeService { ...@@ -67,9 +68,9 @@ public class QCodeService {
byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName); byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData); 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) { } catch (WxErrorException e) {
e.printStackTrace(); e.printStackTrace();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
......
...@@ -43,7 +43,7 @@ public class StorageService { ...@@ -43,7 +43,7 @@ public class StorageService {
* @param contentType 文件类型 * @param contentType 文件类型
* @param fileName 文件索引名 * @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); String key = generateKey(fileName);
storage.store(inputStream, contentLength, contentType, key); storage.store(inputStream, contentLength, contentType, key);
...@@ -56,7 +56,7 @@ public class StorageService { ...@@ -56,7 +56,7 @@ public class StorageService {
storageInfo.setUrl(url); storageInfo.setUrl(url);
litemallStorageService.add(storageInfo); litemallStorageService.add(storageInfo);
return url; return storageInfo;
} }
private String generateKey(String originalFilename) { private String generateKey(String originalFilename) {
......
...@@ -53,11 +53,8 @@ public class WxStorageController { ...@@ -53,11 +53,8 @@ public class WxStorageController {
@PostMapping("/upload") @PostMapping("/upload")
public Object upload(@RequestParam("file") MultipartFile file) throws IOException { public Object upload(@RequestParam("file") MultipartFile file) throws IOException {
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
String url = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename); LitemallStorage litemallStorage = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename);
return ResponseUtil.ok(litemallStorage);
Map<String, Object> data = new HashMap<>();
data.put("url", url);
return ResponseUtil.ok(data);
} }
/** /**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment