本文整理汇总了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;
}
示例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
));
}
示例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();
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}