Commit 1a31f907 authored by 周健威's avatar 周健威

修改代码

parent 65909eff
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
# profiles: # profiles:
# active: dev # active: dev
spring: spring:
# servlet:
# multipart:
# max-file-size: 3000MB
# max-request-size: 3000MB
profiles: profiles:
active: dev active: dev
application: application:
......
package com.upyuns.platform.rs.universal.controller; package com.upyuns.platform.rs.universal.controller;
import cn.hutool.core.img.ImgUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken; import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
...@@ -45,21 +46,21 @@ public class UploadController{ ...@@ -45,21 +46,21 @@ public class UploadController{
@Autowired @Autowired
UploadZipService uploadZipService; UploadZipService uploadZipService;
private static Integer MAX_DRIVING_LICENSE_SIZE = 10 * 1024 * 1024;//10M
@RequestMapping(value = "/app/unauth/upload", method = RequestMethod.POST) @RequestMapping(value = "/app/unauth/upload", method = RequestMethod.POST)
public JSONObject upload( public JSONObject upload(
@RequestParam("file") MultipartFile file, @RequestParam("file") MultipartFile file,
@RequestParam(value = "prefix",defaultValue = "app")String prefix @RequestParam(value = "prefix",defaultValue = "app")String prefix
)throws Exception { )throws Exception {
String contentType = file.getContentType(); //图片文件类型 String contentType = file.getContentType(); //图片文件类型
// String fileName = file.getOriginalFilename(); //图片名字 return JsonResultUtil.createSuccessResultWithObj(uploadService.uploadFile(file,prefix));
/* if (!contentType.equals("image/jpeg") && !contentType.equals("image/gif")&&!contentType.equals("image/png")) {
return JsonResultUtil.createFailedResult(2001,"格式不对!!!");
}*/
if (file.getSize() > MAX_DRIVING_LICENSE_SIZE) {
return JsonResultUtil.createFailedResult(2002,"大小超过限制!!!");
} }
@RequestMapping(value = "/app/unauth/uploadDispose", method = RequestMethod.POST)
public JSONObject uploadDispose(
@RequestParam("file") MultipartFile file,
@RequestParam(value = "prefix",defaultValue = "app")String prefix
)throws Exception {
String contentType = file.getContentType(); //图片文件类型
return JsonResultUtil.createSuccessResultWithObj(uploadService.uploadFile(file,prefix)); return JsonResultUtil.createSuccessResultWithObj(uploadService.uploadFile(file,prefix));
} }
...@@ -82,9 +83,9 @@ public class UploadController{ ...@@ -82,9 +83,9 @@ public class UploadController{
/* if (!contentType.equals("image/jpeg") && !contentType.equals("image/gif")&&!contentType.equals("image/png")) { /* if (!contentType.equals("image/jpeg") && !contentType.equals("image/gif")&&!contentType.equals("image/png")) {
return JsonResultUtil.createFailedResult(2001,"格式不对!!!"); return JsonResultUtil.createFailedResult(2001,"格式不对!!!");
}*/ }*/
if (file.getSize() > MAX_DRIVING_LICENSE_SIZE) { // if (file.getSize() > MAX_DRIVING_LICENSE_SIZE) {
return JsonResultUtil.createFailedResult(2002,"大小超过限制!!!"); // return JsonResultUtil.createFailedResult(2002,"大小超过限制!!!");
} // }
return JsonResultUtil.createSuccessResultWithObj(uploadService.uploadFile(file,prefix)); return JsonResultUtil.createSuccessResultWithObj(uploadService.uploadFile(file,prefix));
} }
...@@ -106,10 +107,10 @@ public class UploadController{ ...@@ -106,10 +107,10 @@ public class UploadController{
MultipartFile file = files[i]; MultipartFile file = files[i];
//保存文件 //保存文件
String contentType = file.getContentType(); String contentType = file.getContentType();
if (file.getSize() > MAX_DRIVING_LICENSE_SIZE) { // if (file.getSize() > MAX_DRIVING_LICENSE_SIZE) {
log.error("大小超过限制!!!"); // log.error("大小超过限制!!!");
continue; // continue;
} // }
String path=uploadService.uploadFile(file,prefix); String path=uploadService.uploadFile(file,prefix);
if(StringUtils.isBlank(urls)){ if(StringUtils.isBlank(urls)){
urls+=path; urls+=path;
......
package com.upyuns.platform.rs.universal.service; package com.upyuns.platform.rs.universal.service;
import cn.hutool.core.img.ImgUtil;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.SystemConfig; import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.upyuns.platform.rs.universal.constant.RedisKey; import com.upyuns.platform.rs.universal.constant.RedisKey;
...@@ -19,7 +20,12 @@ import org.springframework.http.ResponseEntity; ...@@ -19,7 +20,12 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -61,6 +67,41 @@ public class UploadService { ...@@ -61,6 +67,41 @@ public class UploadService {
return realFileRelPath; return realFileRelPath;
} }
/**
* 写入上传文件,返回相对路径
* @param file
* @return
*/
public String uploadFileDispose(MultipartFile file,String prefix) throws Exception{
//创建本日存放目录
DateTime now = DateTime.now();
String dirPathToday = "/"+prefix+ "/" + now.toString(DEFAULT_DATE_TIME_FORMATTER);
String redisNoKey = RedisKey.UPLOAD_FILE_NO_PREFIX + now.toString(DEFAULT_DATE_TIME_FORMATTER);
Long no = redisTemplate.opsForValue().increment(redisNoKey);
if(no.equals(1l)){
redisTemplate.expire(redisNoKey,1, TimeUnit.DAYS);
}
String fileName = file.getOriginalFilename();
String realFileRelPath = dirPathToday + "/" + no + fileName.substring(fileName.lastIndexOf("."));
//文件存放路径
String filePath = baseUploadPath + realFileRelPath;
//缩略
BufferedImage bufferedImage = ImgUtil.read(file.getInputStream());
Float scale = 800f / bufferedImage.getHeight();
Image newImage = ImgUtil.scale(bufferedImage, scale);
//加水印
Image newImage2 = ImgUtil.pressText(newImage, "人民星云", Color.WHITE, null, 0, 0, 0.2f);
//将文件写入指定位置
ImgUtil.write(newImage2, new File(filePath));
//将文件写入指定位置
//FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
realFileRelPath=xx_url+SystemConfig.XXMP_URL+realFileRelPath;
return realFileRelPath;
}
/** /**
* 写入上传文件,返回相对路径 * 写入上传文件,返回相对路径
* @param imgFile * @param imgFile
......
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