Merge remote-tracking branch 'origin/master'
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ public interface IOSSFileService extends IService<OSSFile> {
|
||||
* @param bizPath 自定义路径
|
||||
* @return
|
||||
*/
|
||||
public OSSFile uploadLocal(MultipartFile mf, String bizPath,String state);
|
||||
public OSSFile uploadLocal(MultipartFile mf, String bizPath,String state,String cut);
|
||||
|
||||
|
||||
public List<OSSFile> getFileInfos(String id);
|
||||
|
||||
+22
-6
@@ -2,6 +2,7 @@ package com.jero.modules.oss.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.CommonUtils;
|
||||
@@ -58,13 +59,17 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public OSSFile uploadLocal(MultipartFile mf, String bizPath,String state) {
|
||||
public OSSFile uploadLocal(MultipartFile mf, String bizPath,String state,String cut) {
|
||||
|
||||
//处理文件大小,大于100M抛出异常
|
||||
long fileSize = mf.getSize() / 1024 / 1024;
|
||||
String originalFilename = mf.getOriginalFilename();
|
||||
if (fileSize >= 100) {
|
||||
throw new JeroBootException(originalFilename + "文件大小超出100MB限制, 请压缩或降低文件质量!");
|
||||
if(cut.equals(CutEnum.CN.getValue())){
|
||||
throw new JeroBootException(originalFilename + "文件大小超出100MB, 请压缩或降低文件质量!");
|
||||
}else{
|
||||
throw new JeroBootException(originalFilename + "File size out 100MB, Please compress or reduce file quality!");
|
||||
}
|
||||
}
|
||||
|
||||
OSSFile oSSFile = new OSSFile();
|
||||
@@ -90,11 +95,19 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
|
||||
if("1".equals(state)){
|
||||
//固定文件
|
||||
if(!fileTypeStr.contains(fileType)){
|
||||
throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!");
|
||||
if(cut.equals(CutEnum.CN.getValue())){
|
||||
throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!");
|
||||
}else{
|
||||
throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again!");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) {
|
||||
throw new JeroBootException("不能上传"+StringUtils.join(fileSuffixLimits, ",")+"类型的文件。请重新选择文件!");
|
||||
if(cut.equals(CutEnum.CN.getValue())){
|
||||
throw new JeroBootException("不能上传"+StringUtils.join(fileSuffixLimits, ",")+"类型的文件。请重新选择文件!");
|
||||
}else{
|
||||
throw new JeroBootException("Can't upload"+StringUtils.join(fileSuffixLimits, ",")+"type of file Please select the file again!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,9 +123,12 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!");
|
||||
if(cut.equals(CutEnum.CN.getValue())){
|
||||
throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!");
|
||||
}else{
|
||||
throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String savePath = file.getPath() + File.separator + fileName;
|
||||
|
||||
+9
-3
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.util.RestUtil;
|
||||
@@ -150,7 +151,8 @@ public class CommonController {
|
||||
@ApiOperation(value="文件上传统一方法", notes="文件上传统一方法")
|
||||
@PostMapping(value = "/upload")
|
||||
public Result<?> upload(HttpServletRequest request, HttpServletResponse response,
|
||||
@RequestParam(value = "state",required = false) String state) {
|
||||
@RequestParam(value = "state",required = false) String state,
|
||||
@RequestParam(value = "cut",required = false) String cut) {
|
||||
Result<OSSFile> result = new Result<>();
|
||||
String bizPath = request.getParameter("biz");
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
@@ -163,12 +165,16 @@ public class CommonController {
|
||||
bizPath = "";
|
||||
}
|
||||
}
|
||||
OSSFile oSSFile = ossFileService.uploadLocal(file, bizPath,state);
|
||||
OSSFile oSSFile = ossFileService.uploadLocal(file, bizPath,state,cut);
|
||||
if (oConvertUtils.isNotEmpty(oSSFile)) {
|
||||
result.setResult(oSSFile);
|
||||
result.setSuccess(true);
|
||||
} else {
|
||||
result.setMessage("上传失败!");
|
||||
if("cut".equals(CutEnum.CN.getValue())){
|
||||
result.setMessage("上传失败!");
|
||||
}else{
|
||||
result.setMessage("fail to upload!");
|
||||
}
|
||||
result.setSuccess(false);
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user