FileUploadController.java package com.lincomb.scene.input.controller;import com.lincomb.base.util.Base64;import com.lincomb.base.util.FastdfsUtil;import com.lincomb.scene.input.common.constant.Constant;import com.lincomb.scene.input.common.
package com.lincomb.scene.input.controller; import com.lincomb.base.util.Base64; import com.lincomb.base.util.FastdfsUtil; import com.lincomb.scene.input.common.constant.Constant; import com.lincomb.scene.input.common.controller.BaseController; import com.lincomb.scene.input.common.util.Assert; import com.lincomb.scene.input.enums.RespCode; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.UUID; /** * @Description: * @Author: caijun.wei * @CreateDate:2017-10-21 11:43 * Version: V0.1 */ @Slf4j @Controller @RequestMapping public class FileUploadController extends BaseController { @RequestMapping("fileUpload") public ModelAndView fileUpload(String file) { Assert.isBlank(file, RespCode.REQUEST_PARAM_NULL); file = file.substring(file.indexOf(",") + 1); ModelMap modelMap = new ModelMap(); try { byte[] fContent = Base64.decode(file.getBytes()); String path = FastdfsUtil.upload(fContent, "1.jpg", fContent.length); modelMap.addAttribute("path", path); modelMap.addAttribute(Constant.ResponseVO.CODE, RespCode.RESP_CODE_SUCCESS.getCode()); modelMap.addAttribute(Constant.ResponseVO.MSG, RespCode.RESP_CODE_SUCCESS.getMsg()); }catch (Exception e) { log.error("上传文件失败:" + e.getMessage(), e); modelMap.addAttribute(Constant.ResponseVO.CODE, RespCode.RESP_CODE_FAILER.getCode()); modelMap.addAttribute(Constant.ResponseVO.MSG, RespCode.RESP_CODE_FAILER.getMsg()); } return new ModelAndView("jsonView", modelMap); } /** * 图片上传 * @param files 图片name * @param requestindex.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> multiple>