org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload Java Examples

The following examples show how to use org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload. 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: CertificateController.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 保存证书
 *
 * @return json
 */
@RequestMapping(value = "/saveCertificate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
@OptLog(UserOperateLogV1.OptType.SaveCert)
@Feature(method = MethodFeature.EDIT)
public String saveCertificate() {
    if (ServletFileUpload.isMultipartContent(getRequest())) {
        return NodeForward.requestMultipart(getNode(), getMultiRequest(), NodeUrl.System_Certificate_saveCertificate).toString();
    }
    return NodeForward.request(getNode(), getRequest(), NodeUrl.System_Certificate_saveCertificate).toString();
}
 
Example #2
Source File: MultipartToBase64ConverterServletRequest.java    From AuTe-Framework with Apache License 2.0 5 votes vote down vote up
private List<FileItem> settingsLoadAndParseRequest() throws FileUploadException {
    DiskFileItemFactory factory = new DiskFileItemFactory();
    // files larger than Threshold will be saved to tmpDir on disk
    factory.setSizeThreshold(configProperties.getThresholdTmpFileSize());
    factory.setRepository(tmpDir);

    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setSizeMax(configProperties.getThresholdFilesSize());
    ServletRequestContext uploadContext = new ServletRequestContext(this);
    return upload.parseRequest(uploadContext);
}
 
Example #3
Source File: WebappContext.java    From kbase-doc with Apache License 2.0 5 votes vote down vote up
public WebappContext(ServletContext servletContext, OpenOffice openOffice) {
	DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
	fileUpload = new ServletFileUpload(fileItemFactory);
	if (openOffice.getFileSizeMax() != null) {
		fileUpload.setFileSizeMax(Integer.parseInt(openOffice.getFileSizeMax()));
		logger.info("max file upload size set to " + openOffice.getFileSizeMax());
	} else {
		logger.warn("max file upload size not set");
	}
	
	DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
	if (openOffice.getPort() != null) {
		String ports = openOffice.getPort();
		String[] portArr = ports.split(",");
		int[] portArrInt = new int[portArr.length];
		int i = 0;
		for (String port : portArr){
			portArrInt[i++] = Integer.parseInt(port);
		}
	    configuration.setPortNumbers(portArrInt);
	}
	if (openOffice.getHome() != null) {
	    configuration.setOfficeHome(new File(openOffice.getHome()));
	}
	if (StringUtils.isNotBlank(openOffice.getProfile())) {
	    configuration.setTemplateProfileDir(new File(openOffice.getProfile()));
	}

	officeManager = configuration.buildOfficeManager();
	documentConverter = new OfficeDocumentConverter(officeManager);
}
 
Example #4
Source File: SaltFile.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public static SaltFile create(HttpServletRequest request) {
    try {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        Path tempDir = Files.createTempDirectory("temp");
        factory.setRepository(tempDir.toFile());
        ServletFileUpload upload = new ServletFileUpload(factory);
        List<FileItem> items = upload.parseRequest(new ServletRequestContext(request));
        SaltFile saltFile = new SaltFile();
        for (FileItem item : items) {
            if (item.isFormField()) {
                if ("path".equals(item.getFieldName())) {
                    saltFile.setPath(item.getString());
                } else {
                    saltFile.setTarget(item.getString());
                }
            } else {
                File uploadedFile = new File(String.format("%s/saltfile%s.tmp", tempDir, UUID.randomUUID()));
                item.write(uploadedFile);
                saltFile.setFile(uploadedFile);
            }
        }

        return saltFile;
    } catch (Exception e) {
        throw new StoreFileException("Could not create temp file", e);
    }
}
 
Example #5
Source File: WebappContext.java    From kbase-doc with Apache License 2.0 4 votes vote down vote up
public ServletFileUpload getFileUpload() {
	return fileUpload;
}