perf: 优化头像上传

pull/10/head
Parker 4 years ago
parent 6702de0e8c
commit 20845690c7

@ -17,6 +17,7 @@ package org.opsli.modulars.system.user.web;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.util.CollectionUtils; import com.alibaba.excel.util.CollectionUtils;
@ -61,6 +62,7 @@ import org.opsli.plugins.oss.OssStorageFactory;
import org.opsli.plugins.oss.service.BaseOssStorageService; import org.opsli.plugins.oss.service.BaseOssStorageService;
import org.opsli.plugins.oss.service.OssStorageService; import org.opsli.plugins.oss.service.OssStorageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
@ -215,10 +217,14 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
} }
try { try {
MultipartFile multipartFile = files.get(0);
Resource resource = multipartFile.getResource();
String filename = resource.getFilename();
// 调用OSS 服务保存头像 // 调用OSS 服务保存头像
OssStorageService ossStorageService = OssStorageFactory.INSTANCE.getHandle(); OssStorageService ossStorageService = OssStorageFactory.INSTANCE.getHandle();
BaseOssStorageService.FileAttr fileAttr = ossStorageService.upload( BaseOssStorageService.FileAttr fileAttr = ossStorageService.upload(
files.get(0).getInputStream(), "jpg"); multipartFile.getInputStream(), FileUtil.extName(filename));
UserModel user = UserUtil.getUserBySource(); UserModel user = UserUtil.getUserBySource();
// 更新头像至数据库 // 更新头像至数据库

Loading…
Cancel
Save