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 {
@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,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) {
......
......@@ -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) {
......
......@@ -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);
}
/**
......
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