本文整理匯總了Java中org.apache.commons.fileupload.servlet.ServletFileUpload.setFileSizeMax方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletFileUpload.setFileSizeMax方法的具體用法?Java ServletFileUpload.setFileSizeMax怎麽用?Java ServletFileUpload.setFileSizeMax使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.fileupload.servlet.ServletFileUpload
的用法示例。
在下文中一共展示了ServletFileUpload.setFileSizeMax方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseRequestMultiPartItems
import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類
/**
* Gets the FileItemIterator of the input.
*
* Can be used to process uploads in a streaming fashion. Check out:
* http://commons.apache.org/fileupload/streaming.html
*
* @return the FileItemIterator of the request or null if there was an
* error.
*/
public Optional<List<FormItem>> parseRequestMultiPartItems(String encoding) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(properties.getInt(Constants.PROPERTY_UPLOADS_MAX_SIZE/*Constants.Params.maxUploadSize.name()*/));//Configuration.getMaxUploadSize());
factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); //Configuration.getTmpDir());
//README the file for tmpdir *MIGHT* need to go into Properties
ServletFileUpload upload = new ServletFileUpload(factory);
if(encoding != null)
upload.setHeaderEncoding(encoding);
upload.setFileSizeMax(properties.getInt(Constants.PROPERTY_UPLOADS_MAX_SIZE));
try {
List<FormItem> items = upload.parseRequest(request)
.stream()
.map(item -> new ApacheFileItemFormItem(item))
.collect(Collectors.toList());
return Optional.of(items);
} catch (FileUploadException e) {
//"Error while trying to process mulitpart file upload"
//README: perhaps some logging
}
return Optional.empty();
}
示例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: configFileUpload
import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類
@Override
public void configFileUpload( DiskFileItemFactory fileItemFactory,
ServletFileUpload servletFileUpload )
{
fileItemFactory.setSizeThreshold( BYTE_M * 10 );
fileItemFactory.setRepository( new File( "D:\\appUploads" ) );
servletFileUpload.setFileSizeMax( BYTE_M * 100 );
}
示例4: 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;
}
示例5: init
import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類
public static void init(ServletContext servletContext) {
// 獲取一個臨時目錄(使用 Tomcat 的 work 目錄)
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
// 創建 FileUpload 對象
fileUpload = new ServletFileUpload(new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, repository));
// 設置上傳限製
if (uploadLimit != 0) {
fileUpload.setFileSizeMax(uploadLimit * 1024 * 1024); // 單位為 M
if (logger.isDebugEnabled()) {
logger.debug("[Smart] limit of uploading: {}M", uploadLimit);
}
}
}
示例6: init
import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類
/**
* 初始化
*/
public static void init(ServletContext servletContext) {
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
servletFileUpload = new ServletFileUpload(new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, repository));
int uploadLimit = ConfigHelper.getAppUploadLimit();
if (uploadLimit != 0) {
servletFileUpload.setFileSizeMax(uploadLimit * 1024 * 1024);
}
}
示例7: init
import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類
public static void init(ServletContext servletContext) {
// 獲取一個臨時目錄(使用 Tomcat 的 work 目錄)
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
// 創建 FileUpload 對象
fileUpload = new ServletFileUpload(new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, repository));
// 設置上傳限製
int uploadLimit = FrameworkConstant.UPLOAD_LIMIT;
if (uploadLimit != 0) {
fileUpload.setFileSizeMax(uploadLimit * 1024 * 1024);
}
}
示例8: 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);
}
示例9: 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;
}
示例10: init
import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類
/**
* Init Method
* @param servletContext
*/
public static void init(ServletContext servletContext){
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
// Configure a repository (to ensure a secure temp location is used)
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
factory.setRepository(repository);
fileUpload = new ServletFileUpload(factory);
long fileMaxSize = Express4JConfig.getMaxFileSize();
fileUpload.setFileSizeMax(fileMaxSize);
fileUpload.setHeaderEncoding(DEFAULT_FIELD_ENCODING);
}
示例11: 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;
}
示例12: init
import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類
private void init() {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(maxUploadSize * 2);
servletFileUpload = new ServletFileUpload(factory);
servletFileUpload.setFileSizeMax(maxUploadSize);
servletFileUpload.setSizeMax(maxUploadSize);
if (allowedFormats == null) {
allowedFormats = new HashSet<>();
allowedFormats.add(HTML);
allowedFormats.add(JSON);
}
}
示例13: init
import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類
@PostConstruct
public void init() {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(maxUploadSize * 2);
servletFileUpload = new ServletFileUpload(factory);
servletFileUpload.setFileSizeMax(maxUploadSize);
servletFileUpload.setSizeMax(maxUploadSize);
if ( allowedFormats == null ) {
allowedFormats = new HashSet<String>();
allowedFormats.add(HTML);
allowedFormats.add(JSON);
}
}
示例14: processRequest
import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類
public Object processRequest(HttpServletRequest request) throws Exception {
HttpServletRequestTwsWrapper twsRequest = request instanceof HttpServletRequestTwsWrapper ? (HttpServletRequestTwsWrapper) request : null;
File temporaryFile = null;
try {
// Check multipart request
if (ServletFileUpload.isMultipartContent(request)) {
Engine.logContext.debug("(ServletRequester.initContext) Multipart resquest");
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
// Set factory constraints
factory.setSizeThreshold(1000);
temporaryFile = File.createTempFile("c8o-multipart-files", ".tmp");
int cptFile = 0;
temporaryFile.delete();
temporaryFile.mkdirs();
factory.setRepository(temporaryFile);
Engine.logContext.debug("(ServletRequester.initContext) Temporary folder for upload is : " + temporaryFile.getAbsolutePath());
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Set overall request size constraint
upload.setSizeMax(EnginePropertiesManager.getPropertyAsLong(PropertyName.FILE_UPLOAD_MAX_REQUEST_SIZE));
upload.setFileSizeMax(EnginePropertiesManager.getPropertyAsLong(PropertyName.FILE_UPLOAD_MAX_FILE_SIZE));
// Parse the request
List<FileItem> items = GenericUtils.cast(upload.parseRequest(request));
for (FileItem fileItem : items) {
String parameterName = fileItem.getFieldName();
String parameterValue;
if (fileItem.isFormField()) {
parameterValue = fileItem.getString();
Engine.logContext.trace("(ServletRequester.initContext) Value for field '" + parameterName + "' : " + parameterValue);
} else {
String name = fileItem.getName().replaceFirst("^.*(?:\\\\|/)(.*?)$", "$1");
if (name.length() > 0) {
File wDir = new File(temporaryFile, "" + (++cptFile));
wDir.mkdirs();
File wFile = new File(wDir, name);
fileItem.write(wFile);
fileItem.delete();
parameterValue = wFile.getAbsolutePath();
Engine.logContext.debug("(ServletRequester.initContext) Temporary uploaded file for field '" + parameterName + "' : " + parameterValue);
} else {
Engine.logContext.debug("(ServletRequester.initContext) No temporary uploaded file for field '" + parameterName + "', empty name");
parameterValue = "";
}
}
if (twsRequest != null) {
twsRequest.addParameter(parameterName, parameterValue);
}
}
}
Requester requester = getRequester();
request.setAttribute("convertigo.requester", requester);
Object result = requester.processRequest(request);
processRequestEnd(request, requester);
return result;
} finally {
if (temporaryFile != null) {
try {
Engine.logEngine.debug("(GenericServlet) Removing the temporary file : " + temporaryFile.getAbsolutePath());
FileUtils.deleteDirectory(temporaryFile);
} catch (IOException e) { }
}
}
}
示例15: uploadFiles
import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類
/**
* 파일을 Upload 처리한다.
*
* @param request
* @param where
* @param maxFileSize
* @return
* @throws Exception
*/
public static List<FormBasedFileVo> uploadFiles(
HttpServletRequest request,
String where,
long maxFileSize) throws Exception {
List<FormBasedFileVo> list = new ArrayList<FormBasedFileVo>();
// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload();
upload.setFileSizeMax(maxFileSize); // SizeLimitExceededException
// Parse the request
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();
if (item.isFormField()) {
// System.out.println("Form field '" + name + "' with value '" + Streams.asString(stream) +
// "' detected.");
LOG.info("Form field '" + name + "' with value '" + Streams.asString(stream) + "' detected.");
} else {
// System.out.println("File field '" + name + "' with file name '" + item.getName() + "' detected.");
LOG.info("File field '" + name + "' with file name '" + item.getName() + "' detected.");
if ("".equals(item.getName())) {
continue;
}
// Process the input stream
FormBasedFileVo vo = new FormBasedFileVo();
String tmp = item.getName();
if (tmp.lastIndexOf("\\") >= 0) {
tmp = tmp.substring(tmp.lastIndexOf("\\") + 1);
}
vo.setFileName(tmp);
vo.setContentType(item.getContentType());
vo.setServerSubPath(getTodayString());
vo.setPhysicalName(getPhysicalFileName());
if (tmp.lastIndexOf(".") >= 0) {
vo.setPhysicalName(vo.getPhysicalName() + tmp.substring(tmp.lastIndexOf(".")));
}
long size = saveFile(stream,
new File(WebUtil.filePathBlackList(where) + SEPERATOR + vo.getServerSubPath() + SEPERATOR + vo.getPhysicalName()));
vo.setSize(size);
list.add(vo);
}
}
} else {
throw new IOException("form's 'enctype' attribute have to be 'multipart/form-data'");
}
return list;
}