当前位置: 首页>>代码示例>>Java>>正文


Java ServletFileUpload.isMultipartContent方法代码示例

本文整理汇总了Java中org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent方法的典型用法代码示例。如果您正苦于以下问题:Java ServletFileUpload.isMultipartContent方法的具体用法?Java ServletFileUpload.isMultipartContent怎么用?Java ServletFileUpload.isMultipartContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.fileupload.servlet.ServletFileUpload的用法示例。


在下文中一共展示了ServletFileUpload.isMultipartContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fileUpload

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
 * 上传文件
 *
 * @param param
 * @param request
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity fileUpload(MultipartFileParam param, HttpServletRequest request) {
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if (isMultipart) {
        logger.info("上传文件start。");
        try {
            // 方法1
            //storageService.uploadFileRandomAccessFile(param);
            // 方法2 这个更快点
            storageService.uploadFileByMappedByteBuffer(param);
        } catch (IOException e) {
            e.printStackTrace();
            logger.error("文件上传失败。{}", param.toString());
        }
        logger.info("上传文件end。");
    }
    return ResponseEntity.ok().body("上传成功。");
}
 
开发者ID:Fourwenwen,项目名称:Breakpoint-http,代码行数:28,代码来源:IndexController.java

示例2: getServiceResult

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
	// Check that we have a file upload request
	boolean isMultipart = ServletFileUpload.isMultipartContent(request);

	if (!isMultipart)
		throw new IllegalArgumentException("Not multipart content!");

	FileItemFactory factory = new DiskFileItemFactory();

	// Create a new file upload handler
	ServletFileUpload upload = new ServletFileUpload(factory);

	// Parse the request
	List<FileItem> items = GenericUtils.cast(upload.parseRequest(request));

	// Process the uploaded items
	handleFormFields(request);
	for (FileItem item : items) {
		doUpload(request, document, item);
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:22,代码来源:UploadService.java

示例3: isValidImage

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public static String isValidImage(HttpServletRequest request, MultipartFile file){
    //最大文件大小
    long maxSize = 5242880;
    //定义允许上传的文件扩展名
    HashMap<String, String> extMap = new HashMap<String, String>();
    extMap.put("image", "gif,jpg,jpeg,png,bmp");

    if(!ServletFileUpload.isMultipartContent(request)){
        return "请选择文件";
    }

    if(file.getSize() > maxSize){
        return "上传文件大小超过5MB限制";
    }
    //检查扩展名
    String fileName=file.getOriginalFilename();
    String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
    if(!Arrays.<String>asList(extMap.get("image").split(",")).contains(fileExt)){
        return "上传文件扩展名是不允许的扩展名\n只允许" + extMap.get("image") + "格式";
    }

    return "valid";
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:24,代码来源:QiniuUtil.java

示例4: VariablesBase

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
 * Basic constructor that takes the request object and saves it to be used by the subsequent
 * methods
 * 
 * @param request
 *          HttpServletRequest object originating from the user request.
 */
@SuppressWarnings("unchecked")
public VariablesBase(HttpServletRequest request) {
  if (request == null) {
    // logging exception to obtain stack trace to pinpoint the cause
    log4j.warn("Creating a VariablesBase with a null request", new Exception());
    this.session = new HttpSessionWrapper();
    this.isMultipart = false;
  } else {
    this.session = request.getSession(true);
    this.httpRequest = request;
    this.isMultipart = ServletFileUpload.isMultipartContent(new ServletRequestContext(request));
    if (isMultipart) {
      DiskFileItemFactory factory = new DiskFileItemFactory();
      // factory.setSizeThreshold(yourMaxMemorySize);
      // factory.setRepositoryPath(yourTempDirectory);
      ServletFileUpload upload = new ServletFileUpload(factory);
      // upload.setSizeMax(yourMaxRequestSize);
      try {
        items = upload.parseRequest(request);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:33,代码来源:VariablesBase.java

示例5: SimpleRequestObject

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public SimpleRequestObject(final HttpMethod method,
		final HttpServletRequest req,
		final File tempFolder,
		final long maxDiskFile,
		final int maxMemFile,
		final boolean allowDiskCache) {
	this.method = method;
	this.req = req;
	if(ServletFileUpload.isMultipartContent(req)) {
		this.variableRequestHandler = new VRFile();
	} else {
		this.variableRequestHandler = new VRNormal();
	}
	this.variableRequestHandler.setFileTempDirectory(tempFolder);
	this.variableRequestHandler.setMaxFileUploadSize(maxDiskFile);
	this.variableRequestHandler.setMaxMemFileSize(maxMemFile);
	this.variableRequestHandler.allowFilesOnDisk(allowDiskCache);
	final javax.servlet.http.Cookie[] cs = this.req.getCookies();
	if(cs != null) {
		for(final javax.servlet.http.Cookie c: cs) {
			cookies.put(c.getName(), new HttpCookie(c));
		}
	}
}
 
开发者ID:emily-e,项目名称:webframework,代码行数:25,代码来源:SimpleRequestObject.java

示例6: copy

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
 * Copy all request params from the model.
 *
 * @param m
 *            the model of source
 */
final public void copy(Model m) {

	this.req = m.req;
	this.resp = m.resp;
	this.contentType = m.contentType;
	this.context = m.context;
	this.lang = m.lang;
	this.locale = m.locale;
	this.login = m.login;
	this.method = m.method;
	this.path = m.path;
	this.sid = m.sid;
	this.uri = m.uri;
	this._multipart = ServletFileUpload.isMultipartContent(req);

	if (this._multipart) {
		this.uploads = m.getFiles();
	}

}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:27,代码来源:Model.java

示例7: doPost

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public void doPost(HttpServletRequest req, HttpServletResponse res) {
  boolean isMultipart = ServletFileUpload.isMultipartContent(req);    
  if (!isMultipart && req.getParameter("operation").equals("delete")){      
    handleDelete(req, res);
  }
  if (!isMultipart && req.getParameter("operation").equals("deleteAllForRecord")){      
   handleDeleteAllForRecord(req, res);
 }
  else{     
    try {
      handleUpload(req, res);
      writeOK(res);
    } catch (FileUploadException ex) {      	 
      log.fatal(ex);
      writeError(res, ex);
    }
  }
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:19,代码来源:FileManagerServlet.java

示例8: render

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public void render() throws IOException {
    ctx.getResponse().setCharacterEncoding(charset);
    String s = toString();
    if (wrapMultipart && ServletFileUpload.isMultipartContent(ctx.getRequest()) && !"XMLHttpRequest".equals(ctx.getRequest().getHeader("X-Requested-With"))) {
        ctx.getResponse().setContentType(contentType == null ? "text/html" : contentType);
        PrintWriter pw = ctx.getResponse().getWriter();
        final String s1 = "<textarea>";
        final String s2 = "</textarea>";
        pw.write(s1, 0, s1.length());
        pw.write(s);
        pw.write(s2, 0, s2.length());
        return;
    }
    String ct = contentType;
    if (ct == null) {
        ct = "application/json";
        String ua = ctx.getRequest().getHeader("User-Agent");
        if (ua != null && ua.contains("MSIE")) {
            ct = "text/plain;charset=" + charset;
        }
    }
    ctx.getResponse().setContentType(ct);
    ctx.getResponse().getWriter().write(s);
}
 
开发者ID:kobe2000,项目名称:webwheel,代码行数:25,代码来源:JsonResult.java

示例9: doPost

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
 * Performs an HTTP POST request
 *
 * @param httpServletRequest  The {@link HttpServletRequest} object passed
 *                            in by the servlet engine representing the
 *                            client request to be proxied
 * @param httpServletResponse The {@link HttpServletResponse} object by which
 *                            we can send a proxied response to the client
 */
public void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
        throws IOException, ServletException {
    // Create a standard POST request
    String contentType = httpServletRequest.getContentType();
    String destinationUrl = this.getProxyURL(httpServletRequest);
    debug("POST Request URL: " + httpServletRequest.getRequestURL(),
            "    Content Type: " + contentType,
            " Destination URL: " + destinationUrl);
    PostMethod postMethodProxyRequest = new PostMethod(destinationUrl);
    // Forward the request headers
    setProxyRequestHeaders(httpServletRequest, postMethodProxyRequest);
    setProxyRequestCookies(httpServletRequest, postMethodProxyRequest);
    // Check if this is a mulitpart (file upload) POST
    if (ServletFileUpload.isMultipartContent(httpServletRequest)) {
        this.handleMultipartPost(postMethodProxyRequest, httpServletRequest);
    } else {
        if (contentType == null || PostMethod.FORM_URL_ENCODED_CONTENT_TYPE.equals(contentType)) {
            this.handleStandardPost(postMethodProxyRequest, httpServletRequest);
        } else {
            this.handleContentPost(postMethodProxyRequest, httpServletRequest);
        }
    }
    // Execute the proxy request
    this.executeProxyRequest(postMethodProxyRequest, httpServletRequest, httpServletResponse);
}
 
开发者ID:florinpatrascu,项目名称:jpublish,代码行数:35,代码来源:ProxyServlet.java

示例10: parseParamsAndFillStreams

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public SolrParams parseParamsAndFillStreams( 
    final HttpServletRequest req, ArrayList<ContentStream> streams ) throws Exception
{
  String method = req.getMethod().toUpperCase(Locale.ROOT);
  if ("GET".equals(method) || "HEAD".equals(method)) {
    return SolrRequestParsers.parseQueryString(req.getQueryString());
  }
  if ("POST".equals( method ) ) {
    if (formdata.isFormData(req)) {
      return formdata.parseParamsAndFillStreams(req, streams);
    }
    if (ServletFileUpload.isMultipartContent(req)) {
      return multipart.parseParamsAndFillStreams(req, streams);
    }
    return raw.parseParamsAndFillStreams(req, streams);
  }
  throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unsupported method: "+method );
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:20,代码来源:SolrRequestParsers.java

示例11: parseParamsAndFillStreams

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public SolrParams parseParamsAndFillStreams( 
    final HttpServletRequest req, ArrayList<ContentStream> streams ) throws Exception
{
  String method = req.getMethod().toUpperCase(Locale.ROOT);
  if ("GET".equals(method) || "HEAD".equals(method) 
      || ("PUT".equals(method) && req.getRequestURI().contains("/schema"))) {
    return parseQueryString(req.getQueryString());
  }
  if ("POST".equals( method ) ) {
    if (formdata.isFormData(req)) {
      return formdata.parseParamsAndFillStreams(req, streams);
    }
    if (ServletFileUpload.isMultipartContent(req)) {
      return multipart.parseParamsAndFillStreams(req, streams);
    }
    if (req.getContentType() != null) {
      return raw.parseParamsAndFillStreams(req, streams);
    }
    throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Must specify a Content-Type header with POST requests");
  }
  throw new SolrException(ErrorCode.BAD_REQUEST, "Unsupported method: " + method + " for request " + req);
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:24,代码来源:SolrRequestParsers.java

示例12: getMultipartContent

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public Map<String, FileItem> getMultipartContent() throws FileUploadException, IllegalAccessException {

		if (!ServletFileUpload.isMultipartContent(request))
			throw new IllegalAccessException();

		FileItemFactory factory = new DiskFileItemFactory();
		ServletFileUpload upload = new ServletFileUpload(factory);

		Map<String, FileItem> result = new HashMap<String, FileItem>();

		@SuppressWarnings("unchecked")
		List<FileItem> items = upload.parseRequest(request);
		for (FileItem fi : items) {
			result.put(fi.getFieldName(), fi);
		}
		return result;
	}
 
开发者ID:jkonert,项目名称:socom,代码行数:18,代码来源:SocomRequest.java

示例13: hanldleReq

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
protected String hanldleReq(HttpServletRequest req, HttpServletResponse res)
		throws Exception {
	boolean isMultipart = ServletFileUpload.isMultipartContent(req);
	if (isMultipart) {
		req = new HttpServletReqEx(req);
	}
	String action = req.getParameter("action");
	if (!StringUtils.isNotEmpty(action)) {
		return "pages/join";
	}
	if (StringUtils.equals(action, "reg")) {
		return register(req, res);
	}
	if (StringUtils.equals(action, "checkexist")) {
		checkIdExist(req, res);
		return null;
	}
	return null;
}
 
开发者ID:yufenghua,项目名称:zhaoxi,代码行数:21,代码来源:JoinController.java

示例14: parseParamsAndFillStreams

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public SolrParams parseParamsAndFillStreams( 
    final HttpServletRequest req, ArrayList<ContentStream> streams ) throws Exception
{
  String method = req.getMethod().toUpperCase(Locale.ROOT);
  if ("GET".equals(method) || "HEAD".equals(method) 
      || (("PUT".equals(method) || "DELETE".equals(method))
          && (req.getRequestURI().contains("/schema")
              || req.getRequestURI().contains("/config")))) {
    return parseQueryString(req.getQueryString());
  }
  if ("POST".equals( method ) ) {
    if (formdata.isFormData(req)) {
      return formdata.parseParamsAndFillStreams(req, streams);
    }
    if (ServletFileUpload.isMultipartContent(req)) {
      return multipart.parseParamsAndFillStreams(req, streams);
    }
    if (req.getContentType() != null) {
      return raw.parseParamsAndFillStreams(req, streams);
    }
    throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Must specify a Content-Type header with POST requests");
  }
  throw new SolrException(ErrorCode.BAD_REQUEST, "Unsupported method: " + method + " for request " + req);
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:26,代码来源:SolrRequestParsers.java

示例15: doFilter

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;
    }

    HttpServletRequest httpRequest = (HttpServletRequest) request;

    if (! ServletFileUpload.isMultipartContent(httpRequest)) {
        chain.doFilter(request, response);
        return;
    }

    ServletFileUpload upload = new ServletFileUpload(factory);
    UploadMultipartRequestWrapper multipartRequest = new UploadMultipartRequestWrapper(httpRequest, upload);
    chain.doFilter(multipartRequest, response);
}
 
开发者ID:mymam,项目名称:mymam,代码行数:20,代码来源:UploadMultipartRequestFilter.java


注:本文中的org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。