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


Java ServletFileUpload.setSizeMax方法代码示例

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


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

示例1: getMultipartContentItems

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
private List<FileItem> getMultipartContentItems() throws IOException, FileUploadException {
  List<FileItem> items = null;
  boolean isMultipart = ServletFileUpload.isMultipartContent(req);    
  if (isMultipart) {
    DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setSizeThreshold(0);
    reposDir = new File(FileUtils.getTempDirectory(), File.separatorChar + UUID.randomUUID().toString());
    if (!reposDir.mkdirs()) {
      throw new XSLWebException(String.format("Could not create DiskFileItemFactory repository directory (%s)", reposDir.getAbsolutePath()));
    }
    factory.setRepository(reposDir);
    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setSizeMax(1024 * 1024 * webApp.getMaxUploadSize());
    items = upload.parseRequest(req);      
  }
  return items;
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:18,代码来源:RequestSerializer.java

示例2: map

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public Map<String, Object> map(HttpServletRequest request) {
    ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
    upload.setSizeMax(20 * 1024);
    upload.setFileSizeMax(10 * 1024);

    List<FileItem> items;
    try {
        items = upload.parseRequest(request);
    } catch (FileUploadException e) {
        throw new RequestMappingException("", e);
    }

    return items.stream().map(item -> {
        String key = item.getFieldName();
        if (item.isFormField()) {
            String value = item.getString();
            return new SimpleKeyValue<String, Object>(key, value);
        } else {
            return new SimpleKeyValue<String, Object>(key, item);
        }
    }).collect(Collectors.toMap(
            SimpleKeyValue::getKey,
            SimpleKeyValue::getValue
    ));
}
 
开发者ID:ShotaOd,项目名称:carbon,代码行数:26,代码来源:MultipartFormKeyValueRequestMapper.java

示例3: doPost

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	try {
		DiskFileItemFactory factory = new DiskFileItemFactory();
		factory.setSizeThreshold(4096);
		factory.setRepository(tempPathFile);
		
		ServletFileUpload upload = new ServletFileUpload(factory);
		upload.setSizeMax(4194304); // 设置最大文件尺寸,这里是4MB
		List<FileItem> items = upload.parseRequest(request);// 得到所有的文件
		Iterator<FileItem> i = items.iterator();
		while (i.hasNext()) {
		    FileItem fi = (FileItem) i.next();
		    String fileName = fi.getName();
		    if (fileName != null) {
		     File fullFile = new File(fi.getName());
		     File savedFile = new File(uploadPath, fullFile.getName());
		     fi.write(savedFile);
		    }
		 }

	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:henrybit,项目名称:bird,代码行数:28,代码来源:UploadImage.java

示例4: getItems

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public HashMap getItems(HttpServletRequest request) throws ServiceException{
      HashMap itemMap=null;
try {
              String tempPath = System.getProperty("java.io.tmpdir");
              FileItemFactory factory = new DiskFileItemFactory(4096,new File(tempPath));
              ServletFileUpload upload = new ServletFileUpload(factory);
              upload.setSizeMax(1000000);
              List fileItems = upload.parseRequest(request);
              Iterator iter = fileItems.iterator();
              itemMap=new HashMap();
              while (iter.hasNext()) {
                  FileItem item = (FileItem) iter.next();

                  if (item.isFormField()) {
                      itemMap.put(item.getFieldName(), item.getString());
                  } else {
                      itemMap.put(item.getFieldName(), item);
                  }
              }
      } catch (Exception e) {
              e.printStackTrace();
              throw ServiceException.FAILURE("FileUploadHandler.getItems", e);
      }
      return itemMap;
  }
 
开发者ID:mobilipia,项目名称:Deskera-HRMS,代码行数:26,代码来源:FileUploadHandler.java

示例5: uploadExcel

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public HSSFSheet uploadExcel(HttpServletRequest request)
		throws IOException, FileUploadException {

	ServletFileUpload fileupload = new ServletFileUpload(
			new DiskFileItemFactory());
	fileupload.setSizeMax(1024 * 1024 * 10);
	@SuppressWarnings("unchecked")
	List<FileItem> fileitems = fileupload.parseRequest(request);

	InputStream inputStream = null;

	for (FileItem fileitem : fileitems) {
		if (!fileitem.isFormField()) {
			inputStream = fileitem.getInputStream();
			break;
		}
	}

	HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
	return workbook.getSheetAt(0);

}
 
开发者ID:joaquinaimar,项目名称:wizard,代码行数:24,代码来源:CodeMaintainServiceImpl.java

示例6: uploadFiles

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
private List<FileEntry> uploadFiles(HttpServletRequest request, String spaceGuid)
    throws FileUploadException, IOException, FileStorageException, SLException {
    ServletFileUpload upload = getFileUploadServlet();
    long maxUploadSize = getConfiguration().getMaxUploadSize();
    upload.setSizeMax(maxUploadSize);

    List<FileEntry> uploadedFiles = new ArrayList<FileEntry>();
    FileItemIterator fileItemIterator = null;
    try {
        fileItemIterator = upload.getItemIterator(request);
    } catch (SizeLimitExceededException ex) {
        throw new SLException(MessageFormat.format(Messages.MAX_UPLOAD_SIZE_EXCEEDED, maxUploadSize));
    }
    while (fileItemIterator.hasNext()) {
        FileItemStream item = fileItemIterator.next();
        if (item.isFormField()) {
            continue; // ignore simple (non-file) form fields
        }

        InputStream in = null;
        try {
            in = item.openStream();
            FileEntry entry = getFileService().addFile(spaceGuid, item.getName(),
                getConfiguration().getFileUploadProcessor(), in);
            uploadedFiles.add(entry);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
    return uploadedFiles;
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:32,代码来源:FilesApiServiceImpl.java

示例7: getServletFileUpload

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
private ServletFileUpload getServletFileUpload() {
    ServletFileUpload upload = new ServletFileUpload
            (getDiskFileItemFactory());
    upload.setFileSizeMax(MAX_FILE_SIZE);
    upload.setSizeMax(MAX_REQUEST_SIZE);
    return upload;
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:8,代码来源:FileUploadServlet.java

示例8: newFileUpload

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
protected FileUpload newFileUpload(FileItemFactory fileItemFactory) {
    
    ServletFileUpload upload = new ServletFileUpload(fileItemFactory); 
    upload.setSizeMax(-1); 
    if (request != null) {
        // 注入监听
        FileUploadProgressListener uploadProgressListener = new FileUploadProgressListener();
        upload.setProgressListener(uploadProgressListener);
        request.getSession().setAttribute(C.UPLOAD_PROGRESS_LISTENER_KEY, uploadProgressListener);
    }
    return upload;
}
 
开发者ID:PekingGo,项目名称:ipayquery,代码行数:14,代码来源:CustomMultipartResolver.java

示例9: initFields

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
  * 处理上传内容
  *
  * @param request
  * @param maxSize
  * @return
  */
 // @SuppressWarnings("unchecked")
 private Map<String, Object> initFields(HttpServletRequest request) {

     // 存储表单字段和非表单字段
     Map<String, Object> map = new HashMap<String, Object>();

     // 第一步:判断request
     boolean isMultipart = ServletFileUpload.isMultipartContent(request);
     // 第二步:解析request
     if (isMultipart) {
         // Create a factory for disk-based file items
         DiskFileItemFactory factory = new DiskFileItemFactory();

         // 阀值,超过这个值才会写到临时目录,否则在内存中
         factory.setSizeThreshold(1024 * 1024 * 10);
         factory.setRepository(new File(tempPath));

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

         upload.setHeaderEncoding("UTF-8");

         // 最大上传限制
         upload.setSizeMax(maxSize);

/* FileItem */
         List<FileItem> items = null;
         // Parse the request
         try {
             items = upload.parseRequest(request);
         } catch (FileUploadException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }

         // 第3步:处理uploaded items
         if (items != null && items.size() > 0) {
             Iterator<FileItem> iter = items.iterator();
             // 文件域对象
             List<FileItem> list = new ArrayList<FileItem>();
             // 表单字段
             Map<String, String> fields = new HashMap<String, String>();
             while (iter.hasNext()) {
                 FileItem item = iter.next();
                 // 处理所有表单元素和文件域表单元素
                 if (item.isFormField()) { // 表单元素
                     String name = item.getFieldName();
                     String value = item.getString();
                     fields.put(name, value);
                 } else { // 文件域表单元素
                     list.add(item);
                 }
             }
             map.put(FORM_FIELDS, fields);
             map.put(FILE_FIELDS, list);
         }
     }
     return map;
 }
 
开发者ID:ansafari,项目名称:melon,代码行数:67,代码来源:UploadUtils.java

示例10: Uploader

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
 * 文件上传构造器
 *
 * @param request           {@link HttpServletRequest}
 * @param allowedSuffixList 允许上传的文件后缀
 * @param baseDir           文件上传保存的根目录
 */
public Uploader(HttpServletRequest request, List<String> allowedSuffixList, String baseDir) {
    this.request = request;
    this.allowedSuffixList = allowedSuffixList;
    this.baseDir = baseDir;
    FACTORY.setSizeThreshold(MAX_SIZE_THRESHOLD);
    FACTORY.setRepository(TEMP_REPOSITORY);
    upload = new ServletFileUpload(FACTORY);
    upload.setSizeMax(MAX_SIZE_BYTES);
}
 
开发者ID:glameyzhou,项目名称:scaffold,代码行数:17,代码来源:Uploader.java

示例11: FileUploadWrapper

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/** Constructor.  */
@SuppressWarnings("unchecked")
public FileUploadWrapper(HttpServletRequest aRequest, final ServletContext context,
						final long maxFileSizeBytes, final long maxRequestSizeBytes)
						throws FileUploadException {
	super(aRequest);
	ServletFileUpload upload = new ServletFileUpload( getDiskFileItemFactory(context) );
	
	//Limit the request size and the file size
	upload.setFileSizeMax( maxFileSizeBytes );
	upload.setSizeMax( maxRequestSizeBytes );
	
	List<FileItem> fileItems = upload.parseRequest(aRequest);
	convertToMaps(fileItems);
}
 
开发者ID:ivan-zapreev,项目名称:x-cure-chat,代码行数:16,代码来源:FileUploadWrapper.java

示例12: getFileUploadComponent

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
private ServletFileUpload getFileUploadComponent()
{
    DiskFileItemFactory dif=new DiskFileItemFactory();

    if(factorySizeThreshold!=DEFAULT_SIZE_THRESHOLD)
    {
        dif.setSizeThreshold(factorySizeThreshold);
    }
    if(factoryRepository!=null)
    {
        dif.setRepository(new File(factoryRepository));
    }
    if(factoryCleaningTracker!=null)
    {
        dif.setFileCleaningTracker(factoryCleaningTracker);
    }

    ServletFileUpload sfu=new ServletFileUpload(dif);

    if(sizeMax!=NO_LIMIT_SIZE_MAX)
    {
        sfu.setSizeMax(sizeMax);
    }
    if(fileSizeMax!=NO_LIMIT_FILE_SIZE_MAX)
    {
        sfu.setFileSizeMax(fileSizeMax);
    }
    if(servletHeaderencoding!=null)
    {
        sfu.setHeaderEncoding(servletHeaderencoding);
    }
    if(servletProgressListener!=null)
    {
        sfu.setProgressListener(servletProgressListener);
    }

    return sfu;
}
 
开发者ID:ProteanBear,项目名称:ProteanBear_Java,代码行数:39,代码来源:FileUploader.java

示例13: createServletFileUpload

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
protected ServletFileUpload createServletFileUpload(HttpServletRequest request) {
    final DiskFileItemFactory fileItemFactory = createDiskFileItemFactory();
    final ServletFileUpload upload = newServletFileUpload(fileItemFactory);
    upload.setHeaderEncoding(request.getCharacterEncoding());
    upload.setSizeMax(getSizeMax());
    return upload;
}
 
开发者ID:lastaflute,项目名称:lastaflute-example-harbor,代码行数:8,代码来源:HarborMultipartRequestHandler.java

示例14: parseParamsAndFillStreams

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public SolrParams parseParamsAndFillStreams( 
    final HttpServletRequest req, ArrayList<ContentStream> streams ) throws Exception
{
  if( !ServletFileUpload.isMultipartContent(req) ) {
    throw new SolrException( ErrorCode.BAD_REQUEST, "Not multipart content! "+req.getContentType() );
  }
  
  MultiMapSolrParams params = parseQueryString( req.getQueryString() );
  
  // Create a factory for disk-based file items
  DiskFileItemFactory factory = new DiskFileItemFactory();

  // Set factory constraints
  // TODO - configure factory.setSizeThreshold(yourMaxMemorySize);
  // TODO - configure factory.setRepository(yourTempDirectory);

  // Create a new file upload handler
  ServletFileUpload upload = new ServletFileUpload(factory);
  upload.setSizeMax( ((long) uploadLimitKB) * 1024L );

  // Parse the request
  List items = upload.parseRequest(req);
  Iterator iter = items.iterator();
  while (iter.hasNext()) {
      FileItem item = (FileItem) iter.next();

      // If its a form field, put it in our parameter map
      if (item.isFormField()) {
        MultiMapSolrParams.addParam( 
          item.getFieldName(), 
          item.getString(), params.getMap() );
      }
      // Add the stream
      else { 
        streams.add( new FileItemContentStream( item ) );
      }
  }
  return params;
}
 
开发者ID:europeana,项目名称:search,代码行数:41,代码来源:SolrRequestParsers.java

示例15: createFileUpload

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
private ServletFileUpload createFileUpload(String encoding) {
	DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(_sizeThreshold, _tempDir);
	diskFileItemFactory.setFileCleaningTracker(_fileCleaningTracker);

	ServletFileUpload fileUpload = new ServletFileUpload(diskFileItemFactory);
	fileUpload.setHeaderEncoding(encoding);
	fileUpload.setFileSizeMax(_fileSizeMax);
	fileUpload.setSizeMax(_sizeMax);
	
	//_fileUploadEncodingMap.put(fileUpload.getHeaderEncoding(), fileUpload);
	
	return fileUpload;
}
 
开发者ID:SalamaSoft,项目名称:REST-framework,代码行数:14,代码来源:FileUploadSupport.java


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