Commit a1b1de7a authored by yaobaizheng's avatar yaobaizheng

图片压缩

parent 2fa44890
......@@ -43,7 +43,7 @@ public class SysFileController {
@ApiOperation(value = "华为OBS图片上传",notes = "")
public String uploadImg(MultipartFile file, HttpServletResponse response) throws Exception {
response.setContentType("application/json;charset=GBK");
return lyyConfig.getObsPath() + "/" + uploadService.uploadFile(file,"lyy/img");
return lyyConfig.getObsPath() + "/" + uploadService.uploadImg(file,"lyy/img");
}
@PostMapping("/uploadFileLocal")
......
......@@ -12,6 +12,12 @@ public interface UploadService {
*/
String uploadFile(MultipartFile files, String rootPath) throws Exception;
/**
* @Description: 文件图片
*/
String uploadImg(MultipartFile files,String rootPath) throws Exception;
/**
* @Description: 本地文件上传
*/
......
......@@ -38,7 +38,7 @@ public class UploadServiceImpl implements UploadService {
* @return 文件存储路径
*/
@Override
public String uploadFile(MultipartFile files,String rootPath) throws Exception {
public String uploadImg(MultipartFile files,String rootPath) throws Exception {
//华为obs
if(files == null || files.getSize() == 0){
throw new Exception("请上传文件,文件为空");
......@@ -71,6 +71,23 @@ public class UploadServiceImpl implements UploadService {
return rootPath + filePath;
}
@Override
public String uploadFile(MultipartFile files,String rootPath) throws Exception {
//华为obs
if(files == null || files.getSize() == 0){
throw new Exception("请上传文件,文件为空");
}
String fileOriginalName = files.getOriginalFilename();
String fileLastType = fileOriginalName.substring(files.getOriginalFilename().lastIndexOf("."));
// String date = LocalDateTimeUtils.formatNow("yyyy-MM-dd");
String date = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd");
String newFilename = IdUtil.simpleUUID() + fileLastType;
String filePath = "/" + date + "/" + newFilename;
InputStream inputStream = files.getInputStream();
obsUtils.ObsUpload(bucketName, rootPath + filePath, inputStream);
return rootPath + filePath;
}
@Override
public String uploadFileLocal(MultipartFile files, String rootPath) throws Exception {
//华为obs
......
Markdown is supported
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