當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。