|
|
@@ -0,0 +1,98 @@ |
|
|
|
package com.iformall.controller; |
|
|
|
|
|
|
|
|
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.controller.base.BaseController; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@RestController |
|
|
|
@RequestMapping(value = "upload") |
|
|
|
@Api(description = "文件上传接口") |
|
|
|
public class UploadController extends BaseController { |
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 上传文件 |
|
|
|
* |
|
|
|
* @param multiReq |
|
|
|
* @return |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
@PostMapping(value = "/awsFileUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") |
|
|
|
@ApiOperation("上传文件") |
|
|
|
public ResultData awsfileUpload(@RequestParam("file") MultipartFile multiReq) { |
|
|
|
logger.info("[" + getIpAddr() + "] UploadController::awsfileUpload"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
int dot = multiReq.getOriginalFilename().lastIndexOf('.'); |
|
|
|
String fileFormat = ""; |
|
|
|
if (dot >= 0) { |
|
|
|
fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); |
|
|
|
} |
|
|
|
return new ResultData(fileFormat); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 图片上传 |
|
|
|
* |
|
|
|
* @param multiReq |
|
|
|
* @return |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
@PostMapping(value = "/awsImgUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") |
|
|
|
@ApiOperation("上传图片") |
|
|
|
public ResultData awsImgUpload(@RequestParam("file") MultipartFile multiReq |
|
|
|
, @RequestParam Map<String, String> param) { |
|
|
|
logger.info("[" + getIpAddr() + "] UploadController::awsImgUpload"); |
|
|
|
|
|
|
|
|
|
|
|
long size = multiReq.getSize(); |
|
|
|
final long length = 2097152; |
|
|
|
if (size > length) { |
|
|
|
return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED); |
|
|
|
} |
|
|
|
|
|
|
|
String fileFormat = ""; |
|
|
|
try { |
|
|
|
int dot = multiReq.getOriginalFilename().lastIndexOf('.'); |
|
|
|
if (dot >= 0) { |
|
|
|
fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(fileFormat); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("解析图片",e); |
|
|
|
return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |