Java Code Examples for org.springframework.web.multipart.MultipartHttpServletRequest#getParameter()

The following examples show how to use org.springframework.web.multipart.MultipartHttpServletRequest#getParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccountPersonalController.java    From hermes with Apache License 2.0 6 votes vote down vote up
/**
 * 上传图片信息
 * 
 * @param request
 * @return
 */
@RequestMapping("uploadImage")
@ResponseBody()
public void uploadImage(MultipartHttpServletRequest request) {
	try {
	AppUser curUser = App.current().getUser();
	User user = userInfoService.findByUserId(curUser.getId());
	String label = request.getParameter("label");
	MultipartFile file = request.getFile("file");
		String imgStr = Images.toBase64(Files.getMimeType(file.getOriginalFilename()), file.getBytes());
		userInfoService.saveImage(user, imgStr, com.jlfex.hermes.model.UserImage.Type.AUTH, label);
	} catch (Exception e) {
		Logger.error(e.getMessage(), e);
		throw new ServiceException(e.getMessage(), e);
	}
}
 
Example 2
Source File: Server.java    From feign-form with Apache License 2.0 5 votes vote down vote up
@PostMapping(path = "/upload/byte_array_parameter", consumes = MULTIPART_FORM_DATA_VALUE)
// We just want the request because when there's a filename part of the Content-Disposition header spring
// will treat it as a file (available through getFile()) and when it doesn't have the filename part it's
// available in the parameter (getParameter())
public ResponseEntity<String> uploadByteArrayParameter (MultipartHttpServletRequest request) {
  val status = request.getFile("file") == null && request.getParameter("file") != null
               ? OK
               : I_AM_A_TEAPOT;
  return ResponseEntity.status(status).build();
}
 
Example 3
Source File: AccountPersonalController.java    From hermes with Apache License 2.0 5 votes vote down vote up
/**
 * 修改头像
 * 
 * @param request
 */
@RequestMapping("saveAvatar")
@ResponseBody()
public void saveAvatar(MultipartHttpServletRequest request) {
	AppUser curUser = App.current().getUser();
	User user = userInfoService.findByUserId(curUser.getId());
	String startX = request.getParameter("startX");
	String startY = request.getParameter("startY");
	String width = request.getParameter("width");
	String height = request.getParameter("height");
	String imgWidth = request.getParameter("imgWidth");
	String imgHeight = request.getParameter("imgHeight");
	// 获得文件:
	MultipartFile file = request.getFile("file");
	// 图片裁剪并转为Base64
	Map<String, String> map = Images.crop(file, 
			Integer.valueOf(Strings.empty(startX, "0")), 
			Integer.valueOf(Strings.empty(startY, "0")), 
			Integer.valueOf(Strings.empty(width, "0")), 
			Integer.valueOf(Strings.empty(height,"0")), 
			Integer.valueOf(Strings.empty(imgWidth,"0")), 
			Integer.valueOf(Strings.empty(imgHeight,"0")));
	String avatar = map.get("avatar");
	String avatar_lg = map.get("avatar_lg");
	userInfoService.saveImage(user, avatar, com.jlfex.hermes.model.UserImage.Type.AVATAR, "");
	userInfoService.saveImage(user, avatar_lg, com.jlfex.hermes.model.UserImage.Type.AVATAR_LG, "");
}
 
Example 4
Source File: ApiController.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@ResponseBody
@RequestMapping(value = "/{system}/{domain}/upload")
public String uploadFirmware(
	@PathVariable("system") String system,
	@PathVariable("domain") String domain,
	HttpServletRequest request) {
	//throws Exception {

	String returnMsg = "success";
	Map<String, Object> response = new HashMap<String, Object>();
	
	try{
		//System.out.println("##### get in444! "+system+"/"+domain);
		
		String savePath = "";
		//System.out.println(firmwareDir);
		//System.out.println(tomcatDir+uploadDir);
		//System.out.println("ddddddddd3333");
		
		MultipartHttpServletRequest mptRequest = (MultipartHttpServletRequest)request;
		String originalFileName = mptRequest.getFile("packageName").getOriginalFilename();
		//System.out.println(originalFileName);
		File dir = new File(originalFileName);
		
		if (!dir.exists()) {
			dir.mkdir();
		}
		
		String directory = null;
		int fileType = Integer.parseInt(mptRequest.getParameter("fileType").substring(0, mptRequest.getParameter("fileType").indexOf(" ")));
		if( fileType == 1 ){
			directory = firmwareDir;
		} else {
			directory = tomcatDir+uploadDir;
		}
			
		//System.out.println("middle test : " +dir);
		List<HeritFormBasedFileVO> result = HeritFileUploadUtil.filesUpload(request, directory, maxFileSize);
		//System.out.println(result.size());
		
		String res = null;
		HttpConnector hc = new HttpConnector();
		res = hc.sendFile(mptRequest);
		//System.out.println("---- res : "+res);
		/*
		hc.sendFileWithCurl();

		
		if( result.size() > 0 ){
			
			CurlOperation co = new CurlOperation();
			co.setHeader("fileType", mptRequest.getParameter("fileType"));
			co.setHeader("oui", mptRequest.getParameter("oui"));
			co.setHeader("productClass", mptRequest.getParameter("productClass"));
			co.setHeader("version", mptRequest.getParameter("version"));
			
			Object[] params = new Object[3];
			params[0] = "http://"+HeritProperties.getProperty("Globals.tr069ServerHost")+":"+HeritProperties.getProperty("Globals.tr069ServerPort");
			params[1] = co.getHeader();
			params[2] = firmwareDir+dir.getName();
			
			res = co.send("file upload", params);
			//System.out.println(res);				
		}*/
		
		if(res != null && res.indexOf("201") > -1){
			int deviceModelId = Integer.parseInt(mptRequest.getParameter("deviceModel"));
			//long fileSize = dir.length();
			long fileSize = result.get(0).getSize();
			//System.out.println("######################## file size ");
			//System.out.println(fileSize);
			int fwId = 0;
			String fileName = originalFileName;
			String version = mptRequest.getParameter("version");
			String description = mptRequest.getParameter("description");
			
			fwId = fdao.getFirmwareId(deviceModelId, fileType);
			int fvCount = 0;
			if(fwId == 0){
				fwId = fdao.addFirmwareInfo(deviceModelId, fileName, fileType, description);
				fdao.addFirmwareVersion(fwId, version, fileSize);
			} else {
				fvCount = fdao.getFirmwareVersionCount(fwId, mptRequest.getParameter("version"));
				if(fvCount == 0){
					fdao.addFirmwareVersion(fwId, version, fileSize);
				}
			}
		}
		
	} catch (Exception ex) {
		ex.printStackTrace();
		returnMsg = ex.getMessage();
	}

	return returnMsg;
}
 
Example 5
Source File: WeixinCmsStyleController.java    From jeewx with Apache License 2.0 4 votes vote down vote up
@RequestMapping(params = "upload", method = RequestMethod.POST)
@ResponseBody
public AjaxJson upload(MultipartHttpServletRequest request,
		HttpServletResponse response) {
	AjaxJson j = new AjaxJson();
	// 获取模板ID
	String id = request.getParameter("id");
	Map<String, Object> attributes = new HashMap<String, Object>();
	TSTypegroup tsTypegroup = systemService.getTypeGroup("fieltype", "文档分类");
	TSType tsType = systemService.getType("files", "附件", tsTypegroup);
	String fileKey = oConvertUtils.getString(request.getParameter("fileKey"));// 文件ID
	String documentTitle = oConvertUtils.getString(request
			.getParameter("documentTitle"));// 文件标题
	TSDocument document = new TSDocument();
	if (StringUtil.isNotEmpty(fileKey)) {
		document.setId(fileKey);
		document = systemService.getEntity(TSDocument.class, fileKey);
		document.setDocumentTitle(documentTitle);

	}
	document.setSubclassname(MyClassLoader.getPackPath(document));
	document.setCreatedate(DateUtils.gettimestamp());
	document.setTSType(tsType);
	UploadFile uploadFile = new UploadFile(request, document);
	uploadFile.setCusPath("files");
	uploadFile.setSwfpath("swfpath");
	document = systemService.uploadFile(uploadFile);
	// 获取持久对象
	WeixinCmsStyleEntity weixinCmsStyle = weixinCmsStyleService.getEntity(
			WeixinCmsStyleEntity.class, id);
	// 定义模板路径,规则为:template/cms/{userid}/模板名称
	String requestPath = request.getSession().getServletContext().getRealPath("/template/cms");
	// 硬盘存储路径,即解压路径
	String realpath = requestPath + "/"+ weixinCmsStyle.getAccountid() + "/"+ weixinCmsStyle.getTemplateUrl()+"/";
	File tempfolder = new File(realpath);
	if (!tempfolder.exists()) {
		// 创建模板文件夹路径
		tempfolder.mkdirs();
	}
	weixinCmsStyleService.updateEntitie(weixinCmsStyle);
	try {
		String path = request.getSession().getServletContext().getRealPath("/")+ document.getRealpath();
		ZipUtil.unZip(path,tempfolder.getAbsolutePath()+"/");
	} catch (Exception e) {
		e.printStackTrace();
	}
	attributes.put("url", document.getRealpath());
	attributes.put("fileKey", document.getId());
	attributes.put("name", document.getAttachmenttitle());
	attributes.put("viewhref", "commonController.do?openViewFile&fileid="+ document.getId());
	attributes.put("delurl", "commonController.do?delObjFile&fileKey="+ document.getId());
	j.setMsg("文件添加成功");
	j.setAttributes(attributes);
	return j;
}
 
Example 6
Source File: ApiController.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@ResponseBody
@RequestMapping(value = "/{system}/{domain}/upload")
public String uploadFirmware(
	@PathVariable("system") String system,
	@PathVariable("domain") String domain,
	HttpServletRequest request) {
	//throws Exception {

	String returnMsg = "success";
	Map<String, Object> response = new HashMap<String, Object>();
	
	try{
		//System.out.println("##### get in444! "+system+"/"+domain);
		
		String savePath = "";
		//System.out.println(firmwareDir);
		//System.out.println(tomcatDir+uploadDir);
		//System.out.println("ddddddddd3333");
		
		MultipartHttpServletRequest mptRequest = (MultipartHttpServletRequest)request;
		String originalFileName = mptRequest.getFile("packageName").getOriginalFilename();
		//System.out.println(originalFileName);
		File dir = new File(originalFileName);
		
		if (!dir.exists()) {
			dir.mkdir();
		}
		
		String directory = null;
		int fileType = Integer.parseInt(mptRequest.getParameter("fileType").substring(0, mptRequest.getParameter("fileType").indexOf(" ")));
		if( fileType == 1 ){
			directory = firmwareDir;
		} else {
			directory = tomcatDir+uploadDir;
		}
			
		//System.out.println("middle test : " +dir);
		List<HeritFormBasedFileVO> result = HeritFileUploadUtil.filesUpload(request, directory, maxFileSize);
		//System.out.println(result.size());
		
		String res = null;
		HttpConnector hc = new HttpConnector();
		res = hc.sendFile(mptRequest);
		//System.out.println("---- res : "+res);
		/*
		hc.sendFileWithCurl();

		
		if( result.size() > 0 ){
			
			CurlOperation co = new CurlOperation();
			co.setHeader("fileType", mptRequest.getParameter("fileType"));
			co.setHeader("oui", mptRequest.getParameter("oui"));
			co.setHeader("productClass", mptRequest.getParameter("productClass"));
			co.setHeader("version", mptRequest.getParameter("version"));
			
			Object[] params = new Object[3];
			params[0] = "http://"+HeritProperties.getProperty("Globals.tr069ServerHost")+":"+HeritProperties.getProperty("Globals.tr069ServerPort");
			params[1] = co.getHeader();
			params[2] = firmwareDir+dir.getName();
			
			res = co.send("file upload", params);
			//System.out.println(res);				
		}*/
		
		if(res != null && res.indexOf("201") > -1){
			int deviceModelId = Integer.parseInt(mptRequest.getParameter("deviceModel"));
			//long fileSize = dir.length();
			long fileSize = result.get(0).getSize();
			//System.out.println("######################## file size ");
			//System.out.println(fileSize);
			int fwId = 0;
			String fileName = originalFileName;
			String version = mptRequest.getParameter("version");
			String description = mptRequest.getParameter("description");
			
			fwId = fdao.getFirmwareId(deviceModelId, fileType);
			int fvCount = 0;
			if(fwId == 0){
				fwId = fdao.addFirmwareInfo(deviceModelId, fileName, fileType, description);
				fdao.addFirmwareVersion(fwId, version, fileSize);
			} else {
				fvCount = fdao.getFirmwareVersionCount(fwId, mptRequest.getParameter("version"));
				if(fvCount == 0){
					fdao.addFirmwareVersion(fwId, version, fileSize);
				}
			}
		}
		
	} catch (Exception ex) {
		ex.printStackTrace();
		returnMsg = ex.getMessage();
	}

	return returnMsg;
}
 
Example 7
Source File: ContentController.java    From hermes with Apache License 2.0 4 votes vote down vote up
/**
 * 添加图片管理处理逻辑
 * 
 * @author lishunfeng
 */
@RequestMapping("/handerAddImageManage")
@ResponseBody
public ResultVo handerAddImageManage(MultipartHttpServletRequest request, RedirectAttributes attr) {
	try {
		String type = request.getParameter("type");
		String name = request.getParameter("name");
		String link = request.getParameter("link");
		int order = Integer.parseInt(request.getParameter("order"));
		String imgStr = "";
		MultipartFile file = request.getFile("file");
		BufferedImage buffImage = ImageIO.read(file.getInputStream());
		if (type.equals(HermesConstants.BANNER)) {
			if (buffImage.getWidth() < 1920 || buffImage.getHeight() < 390) {
				return new ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR, "您上传的图片尺寸过小,标准尺寸为1920*390!");
			} else if (buffImage.getWidth() > 1920 || buffImage.getHeight() > 390) {
				// new ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR,
				// "您上传的图片尺寸过大,标准尺寸为1920*390,将为您压缩后继续上传!");
				imgStr = Images.resizeImageToBase64(file, 0, 0, 1920, 390);
			} else {
				imgStr = Images.toBase64(Files.getMimeType(file.getOriginalFilename()), file.getBytes());
			}
		} else if (type.equals(HermesConstants.INVEST) || type.equals(HermesConstants.LOAN)) {
			if (buffImage.getWidth() < 132 || buffImage.getHeight() < 117) {
				return new ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR, "您上传的图片尺寸过大,标准尺寸为132*117!");
			} else if (buffImage.getWidth() > 132 || buffImage.getHeight() > 117) {
				// new ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR,
				// "您上传的图片尺寸过大,标准尺寸为132*117,将为您压缩后继续上传!");
				imgStr = Images.resizeImageToBase64(file, 0, 0, 132, 117);
			} else {
				imgStr = Images.toBase64(Files.getMimeType(file.getOriginalFilename()), file.getBytes());
			}
		} else if (type.equals(HermesConstants.LOGIN) || type.equals(HermesConstants.REGISTER)) {
			if (buffImage.getWidth() < 440 || buffImage.getHeight() < 250) {
				return new ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR, "您上传的图片尺寸过小,标准尺寸为440*250!");
			} else if (buffImage.getWidth() > 440 || buffImage.getHeight() > 250) {
				// new ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR,
				// "您上传的图片尺寸过大,标准尺寸为440*250,将为您压缩后继续上传!");
				imgStr = Images.resizeImageToBase64(file, 0, 0, 440, 250);
			} else {
				imgStr = Images.toBase64(Files.getMimeType(file.getOriginalFilename()), file.getBytes());
			}
		}
		contentService.addImageManage(type, name, link, order, imgStr);
		return new ResultVo(HermesConstants.RESULT_VO_CODE_SUCCESS, "添加图片成功");
	} catch (Exception e) {
		Logger.error("添加图片失败:", e);
		return new ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR, "添加图片失败");
	}
}
 
Example 8
Source File: ContentController.java    From hermes with Apache License 2.0 4 votes vote down vote up
/**
 * 点击编辑图片管理页面保存按钮处理逻辑
 * 
 * @author lishunfeng
 */
@RequestMapping("/handerEditImageManage")
@ResponseBody
public ResultVo handerEditImageManage(MultipartHttpServletRequest request, RedirectAttributes attr, Model model) {
	try {
		String id = request.getParameter("id");
		String type = request.getParameter("type");
		String name = request.getParameter("name");
		String link = request.getParameter("link");
		int order = Integer.parseInt(request.getParameter("order"));
		String imgStr = null;
		MultipartFile file = request.getFile("file");
		if (file != null) {
			BufferedImage buffImage = ImageIO.read(file.getInputStream());
			if (HermesConstants.BANNER.equals(type)) {
				if (buffImage.getWidth() < 1920 || buffImage.getHeight() < 390) {
					return new ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR, "您上传的图片尺寸过小,标准尺寸为1920*390!");
				} else if (buffImage.getWidth() > 1920 || buffImage.getHeight() > 390) {
					// new
					// ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR,
					// "您上传的图片尺寸过大,标准尺寸为1920*390,将为您压缩后继续上传!");
					imgStr = Images.resizeImageToBase64(file, 0, 0, 1920, 390);
				} else {
					imgStr = Images.toBase64(Files.getMimeType(file.getOriginalFilename()), file.getBytes());
				}
			} else if (HermesConstants.INVEST.equals(type) || HermesConstants.LOAN.equals(type)) {
				if (buffImage.getWidth() < 132 || buffImage.getHeight() < 117) {
					return new ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR, "您上传的图片尺寸过大,标准尺寸为132*117!");
				} else if (buffImage.getWidth() > 132 || buffImage.getHeight() > 117) {
					// new
					// ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR,
					// "您上传的图片尺寸过大,标准尺寸为132*117,将为您压缩后继续上传!");
					imgStr = Images.resizeImageToBase64(file, 0, 0, 132, 117);
				} else {
					imgStr = Images.toBase64(Files.getMimeType(file.getOriginalFilename()), file.getBytes());
				}
			} else if (HermesConstants.LOGIN.equals(type) || HermesConstants.REGISTER.equals(type)) {
				if (buffImage.getWidth() < 440 || buffImage.getHeight() < 250) {
					return new ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR, "您上传的图片尺寸过小,标准尺寸为440*250!");
				} else if (buffImage.getWidth() > 440 || buffImage.getHeight() > 250) {
					// new
					// ResultVo(HermesConstants.RESULT_VO_CODE_BIZ_ERROR,
					// "您上传的图片尺寸过大,标准尺寸为440*250,将为您压缩后继续上传!");
					imgStr = Images.resizeImageToBase64(file, 0, 0, 440, 250);
				} else {
					imgStr = Images.toBase64(Files.getMimeType(file.getOriginalFilename()), file.getBytes());
				}
			}
		}
		contentService.updateImageManage(id, type, name, link, order, imgStr);
		return new ResultVo(HermesConstants.RESULT_VO_CODE_SUCCESS, "修改图片成功");
	} catch (Exception e) {
		Logger.error("修改图片失败:", e);
		return new ResultVo(HermesConstants.RESULT_VO_CODE_SUCCESS, "修改图片失败");
	}
}
 
Example 9
Source File: FileControllerServiceImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ModelAndView addFileUploadLine(final UifFormBase form) {
    form.setAjaxReturnType(UifConstants.AjaxReturnTypes.UPDATECOMPONENT.getKey());
    form.setAjaxRequest(true);

    MultipartHttpServletRequest request = (MultipartHttpServletRequest) form.getRequest();

    final String collectionId = request.getParameter(UifParameters.UPDATE_COMPONENT_ID);
    final String bindingPath = request.getParameter(UifConstants.PostMetadata.BINDING_PATH);

    Class<?> collectionObjectClass = (Class<?>) form.getViewPostMetadata().getComponentPostData(collectionId,
            UifConstants.PostMetadata.COLL_OBJECT_CLASS);

    Iterator<String> fileNamesItr = request.getFileNames();

    while (fileNamesItr.hasNext()) {
        String propertyPath = fileNamesItr.next();

        MultipartFile uploadedFile = request.getFile(propertyPath);

        final FileMeta fileObject = (FileMeta) KRADUtils.createNewObjectFromClass(collectionObjectClass);
        try {
            fileObject.init(uploadedFile);
        } catch (Exception e) {
            throw new RuntimeException("Unable to initialize new file object", e);
        }

        String id = UUID.randomUUID().toString() + "_" + uploadedFile.getName();
        fileObject.setId(id);

        fileObject.setDateUploaded(new Date());

        fileObject.setUrl("?methodToCall=getFileFromLine&formKey="
                + form.getFormKey()
                + "&fileName="
                + fileObject.getName()
                + "&propertyPath="
                + propertyPath);

        ViewLifecycle.encapsulateLifecycle(form.getView(), form, form.getViewPostMetadata(), null, request,
                new Runnable() {
                    @Override
                    public void run() {
                        ViewLifecycle.getHelper().processAndAddLineObject(form, fileObject, collectionId,
                                bindingPath);
                    }
                });
    }

    return getModelAndViewService().getModelAndView(form);
}