package com.maizuo.web.controller;
import com.maizuo.domain.Result;
import com.maizuo.util.ConstantsConfig;
import com.maizuo.util.Upload;
import hyxlog.Log;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.List;
/**
* Created by qiyang on 2015/6/15 and improved by heisenberg on 2016/04/18
*/
@Controller
@RequestMapping("/api/upload")
public class UploadController {
@RequestMapping(value = "/img", method = RequestMethod.POST)
@ResponseBody
public Result uploadImg(@RequestParam(value = "file", required = false) MultipartFile file, String pathName,
Integer sizeRule, Integer isDeviation, HttpServletRequest request)
throws FileNotFoundException, IOException {
String loghead = "通用接口-上传图片:";
JSONObject json = new JSONObject();
if (file == null) {
Log.info(loghead + "上传失败:文件为空");
return new Result(900001, "", "上传失败:文件为空");
}
if (StringUtils.isBlank(pathName)) {
pathName = ConstantsConfig.getString("DEFALTUPLOADPATH");
}
List<Object> uploadPathNames =
springmvc处理上传图片代码(校验图片尺寸、图片大小)
最新推荐文章于 2024-07-14 03:25:25 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)