|
|
@ -92,7 +92,7 @@ public class FileUploadServiceImpl implements IFileUploadService {
|
|
|
|
|
|
|
|
|
|
|
|
uploadFileVOList.add(actionUploadFile(multipartFile, pathKey, height, widthStart, widthEnd));
|
|
|
|
uploadFileVOList.add(actionUploadFile(multipartFile, pathKey, height, widthStart, widthEnd));
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(multipartFile.getOriginalFilename() + "====图片压缩和剪切总耗时=======>" + watch.elapsedTime() + "(ms)" + "<===========");
|
|
|
|
System.out.println(multipartFile.getOriginalFilename() + "====图片上传总耗时=======>" + watch.elapsedTime() + "(ms)" + "<===========");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return uploadFileVOList;
|
|
|
|
return uploadFileVOList;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -109,7 +109,6 @@ public class FileUploadServiceImpl implements IFileUploadService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String fileName = path + multipartFile.getOriginalFilename();
|
|
|
|
String fileName = path + multipartFile.getOriginalFilename();
|
|
|
|
|
|
|
|
|
|
|
|
File dest = new File(saveFilePath + fileName);
|
|
|
|
File dest = new File(saveFilePath + fileName);
|
|
|
|
|
|
|
|
|
|
|
|
UploadFileVO uploadFileVO = new UploadFileVO();
|
|
|
|
UploadFileVO uploadFileVO = new UploadFileVO();
|
|
|
@ -120,57 +119,65 @@ public class FileUploadServiceImpl implements IFileUploadService {
|
|
|
|
uploadFileVO.setFilePath(fileName);
|
|
|
|
uploadFileVO.setFilePath(fileName);
|
|
|
|
uploadFileVO.setSaveFilePath(saveFilePath);
|
|
|
|
uploadFileVO.setSaveFilePath(saveFilePath);
|
|
|
|
uploadFileVO.setParams(ParamsUtils.addParam("compressWidth", compressWidth).addParam("widthStart", widthStart).addParam("heightStart", heightStart).param());
|
|
|
|
uploadFileVO.setParams(ParamsUtils.addParam("compressWidth", compressWidth).addParam("widthStart", widthStart).addParam("heightStart", heightStart).param());
|
|
|
|
|
|
|
|
uploadFileVO.setSaveCutFilePath(saveCutFilePath);
|
|
|
|
|
|
|
|
uploadFileVO.setSaveCompressFilePath(saveCompressFilePath);
|
|
|
|
|
|
|
|
multipartFile.transferTo(dest);
|
|
|
|
|
|
|
|
return uploadFileVO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Func.isNotBlank(saveCompressFilePath)) {
|
|
|
|
|
|
|
|
File compressFileDir = new File(saveCompressFilePath + path);
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void compressFile(String compressPath,String picPath,String fileName,Double compressWidth) {
|
|
|
|
|
|
|
|
if (Func.isNotBlank(compressPath)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
File compressFileDir = new File(compressPath);
|
|
|
|
if (!compressFileDir.exists()) {
|
|
|
|
if (!compressFileDir.exists()) {
|
|
|
|
compressFileDir.mkdirs();
|
|
|
|
compressFileDir.mkdirs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
File compressDest = new File(saveCompressFilePath+fileName);
|
|
|
|
File compressDest = new File(saveCompressFilePath+fileName);
|
|
|
|
|
|
|
|
BufferedImage image = ImageIO.read(new File(picPath));
|
|
|
|
BufferedImage image = ImageIO.read(multipartFile.getInputStream());
|
|
|
|
|
|
|
|
int width = image.getWidth();
|
|
|
|
int width = image.getWidth();
|
|
|
|
|
|
|
|
|
|
|
|
//图片压缩
|
|
|
|
//图片压缩
|
|
|
|
ImgUtil.scale(image, FileUtil.file(compressDest), (float) (compressWidth / width));
|
|
|
|
ImgUtil.scale(image, FileUtil.file(compressDest), (float) (compressWidth / width));
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
uploadFileVO.setSaveCompressFilePath(saveCompressFilePath);
|
|
|
|
}finally {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void cutPic(String saveCutFilePath,String compressPath,String fileName,Double widthStart, Double heightStart){
|
|
|
|
if (Func.isNotBlank(saveCutFilePath)) {
|
|
|
|
if (Func.isNotBlank(saveCutFilePath)) {
|
|
|
|
File cutFileDir = new File(saveCutFilePath + path);
|
|
|
|
try {
|
|
|
|
|
|
|
|
File cutFileDir = new File(saveCutFilePath + fileName);
|
|
|
|
if (!cutFileDir.exists()) {
|
|
|
|
if (!cutFileDir.exists()) {
|
|
|
|
cutFileDir.mkdirs();
|
|
|
|
cutFileDir.mkdirs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
File cutDest = new File(saveCutFilePath + fileName);
|
|
|
|
File cutDest = new File(saveCutFilePath + fileName);
|
|
|
|
|
|
|
|
|
|
|
|
BufferedImage image = ImageIO.read(FileUtil.file(saveCompressFilePath + fileName));
|
|
|
|
BufferedImage image = ImageIO.read(FileUtil.file(compressPath+fileName));
|
|
|
|
int height = image.getHeight();
|
|
|
|
int height = image.getHeight();
|
|
|
|
int width = image.getWidth();
|
|
|
|
int width = image.getWidth();
|
|
|
|
int minX = image.getMinX();
|
|
|
|
|
|
|
|
int minY = image.getMinY();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int startY = height / 100 * widthStart.intValue();
|
|
|
|
int startY = height / 100 * widthStart.intValue();
|
|
|
|
int endY = height / 100 * (heightStart.intValue() - widthStart.intValue());
|
|
|
|
int endY = height / 100 * (heightStart.intValue() - widthStart.intValue());
|
|
|
|
|
|
|
|
|
|
|
|
log.info("cutInfo :" +height +" "+width+" "+startY+" "+endY);
|
|
|
|
|
|
|
|
//剪切
|
|
|
|
//剪切
|
|
|
|
ImgUtil.cut(image, FileUtil.file(cutDest), new Rectangle(0, startY, width, endY));
|
|
|
|
ImgUtil.cut(image, FileUtil.file(cutDest), new Rectangle(0, startY, width, endY));
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
uploadFileVO.setWidth(width);
|
|
|
|
}finally {
|
|
|
|
uploadFileVO.setHeight(height);
|
|
|
|
}
|
|
|
|
uploadFileVO.setX(minX);
|
|
|
|
|
|
|
|
uploadFileVO.setY(minY);
|
|
|
|
|
|
|
|
uploadFileVO.setSaveCutFilePath(saveCutFilePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
multipartFile.transferTo(dest);
|
|
|
|
|
|
|
|
return uploadFileVO;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void downloadFile(String path, HttpServletResponse response) {
|
|
|
|
public void downloadFile(String path, HttpServletResponse response) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//创建输入流
|
|
|
|
|
|
|
|
FileInputStream inputStream = null;
|
|
|
|
|
|
|
|
BufferedInputStream buffInputStream = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//创建输出流
|
|
|
|
|
|
|
|
ServletOutputStream outputStream = null;
|
|
|
|
|
|
|
|
BufferedOutputStream buffOutputStream = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//获取要下载的文件
|
|
|
|
//获取要下载的文件
|
|
|
|
// File file = new File(saveFilePath + "/" + path);
|
|
|
|
// File file = new File(saveFilePath + "/" + path);
|
|
|
@ -183,12 +190,12 @@ public class FileUploadServiceImpl implements IFileUploadService {
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
|
|
|
|
|
|
|
|
|
|
|
//创建输入流
|
|
|
|
//创建输入流
|
|
|
|
FileInputStream inputStream = new FileInputStream(file);
|
|
|
|
inputStream = new FileInputStream(file);
|
|
|
|
BufferedInputStream buffInputStream = new BufferedInputStream(inputStream);
|
|
|
|
buffInputStream = new BufferedInputStream(inputStream);
|
|
|
|
|
|
|
|
|
|
|
|
//创建输出流
|
|
|
|
//创建输出流
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
|
|
outputStream = response.getOutputStream();
|
|
|
|
BufferedOutputStream buffOutputStream = new BufferedOutputStream(outputStream);
|
|
|
|
buffOutputStream = new BufferedOutputStream(outputStream);
|
|
|
|
|
|
|
|
|
|
|
|
//循环读取数据并写入到响应输出流中
|
|
|
|
//循环读取数据并写入到响应输出流中
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
@ -206,6 +213,20 @@ public class FileUploadServiceImpl implements IFileUploadService {
|
|
|
|
inputStream.close();
|
|
|
|
inputStream.close();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
}finally {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (inputStream!=null){
|
|
|
|
|
|
|
|
inputStream.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffOutputStream!=null){
|
|
|
|
|
|
|
|
buffOutputStream.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outputStream!=null){
|
|
|
|
|
|
|
|
outputStream.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|