java setmaxfilesize,Java ServletFileUpload.setFileSizeMax方法代碼示例

java setmaxfilesize,Java ServletFileUpload.setFileSizeMax方法代碼示例本文整理匯總了Java中org.apache.commons.fileupload.servlet.ServletFileUpload.setFileSizeMax方法的典型用法代碼示例。如果您正苦於以下問題:JavaServletFileUpload.setFileSizeMax方法的具體用法?JavaServletFileUpload.setFileSizeMax怎麽用?JavaServ…

本文整理匯總了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方法的17個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: parseRequestMultiPartItems

​點讚 3

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> 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 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();

}

開發者ID:MTDdk,項目名稱:jawn,代碼行數:34,

示例2: map

​點讚 3

import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類

public Map map(HttpServletRequest request) {

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

upload.setSizeMax(20 * 1024);

upload.setFileSizeMax(10 * 1024);

List 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(key, value);

} else {

return new SimpleKeyValue(key, item);

}

}).collect(Collectors.toMap(

SimpleKeyValue::getKey,

SimpleKeyValue::getValue

));

}

開發者ID:ShotaOd,項目名稱:carbon,代碼行數:26,

示例3: configFileUpload

​點讚 2

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 );

}

開發者ID:guanhaobi,項目名稱:DataStage,代碼行數:9,

示例4: getServletFileUpload

​點讚 2

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,

示例5: init

​點讚 2

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);

}

}

}

開發者ID:thinkhoon,項目名稱:tkhoon,代碼行數:14,

示例6: init

​點讚 2

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);

}

}

開發者ID:edagarli,項目名稱:Nicole,代碼行數:12,

示例7: init

​點讚 2

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);

}

}

開發者ID:wsldl123292,項目名稱:testeverything,代碼行數:12,

示例8: FileUploadWrapper

​點讚 2

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 fileItems = upload.parseRequest(aRequest);

convertToMaps(fileItems);

}

開發者ID:ivan-zapreev,項目名稱:x-cure-chat,代碼行數:16,

示例9: getFileUploadComponent

​點讚 2

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,

示例10: init

​點讚 2

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);

}

開發者ID:aCoder2013,項目名稱:Express4J,代碼行數:16,

示例11: createFileUpload

​點讚 2

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,

示例12: init

​點讚 2

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);

}

}

開發者ID:rancher,項目名稱:cattle,代碼行數:15,

示例13: init

​點讚 2

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();

allowedFormats.add(HTML);

allowedFormats.add(JSON);

}

}

開發者ID:rancher,項目名稱:gdapi-java-server,代碼行數:16,

示例14: processRequest

​點讚 2

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 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) { }

}

}

}

開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:78,

示例15: uploadFiles

​點讚 2

import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類

/**

* 파일을 Upload 처리한다.

*

* @param request

* @param where

* @param maxFileSize

* @return

* @throws Exception

*/

public static List uploadFiles(

HttpServletRequest request,

String where,

long maxFileSize) throws Exception {

List list = new ArrayList();

// 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;

}

開發者ID:aramsoft,項目名稱:aramcomp,代碼行數:75,

示例16: uploadFiles

​點讚 2

import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類

/**

* 파일을 Upload 처리한다.

*

* @param request

* @param where

* @param maxFileSize

* @return

* @throws Exception

*/

public static List uploadFiles(HttpServletRequest request, String where, long maxFileSize) throws Exception {

List list = new ArrayList();

// 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.”);

Logger.getLogger(HeritFormBasedFileUtil.class).info(“Form field ‘” + name + “‘ with value ‘” + Streams.asString(stream) + “‘ detected.”);

} else {

//System.out.println(“File field ‘” + name + “‘ with file name ‘” + item.getName() + “‘ detected.”);

Logger.getLogger(HeritFormBasedFileUtil.class).info(“File field ‘” + name + “‘ with file name ‘” + item.getName() + “‘ detected.”);

if (“”.equals(item.getName())) {

continue;

}

// Process the input stream

HeritFormBasedFileVO vo = new HeritFormBasedFileVO();

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(HeritWebUtil.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;

}

開發者ID:iotoasis,項目名稱:SI,代碼行數:69,

示例17: MultipartWrapper

​點讚 2

import org.apache.commons.fileupload.servlet.ServletFileUpload; //導入方法依賴的package包/類

/**

* Construct with a current HTTP servlet request.

* @param request the current HTTP servlet request

* @throws FileUploadException if an exception occurs during file upload

*/

public MultipartWrapper(HttpServletRequest request)

throws FileUploadException {

super(request);

getLogger().finer(“Handling multipart content.”);

// initialize parameters

_fileParameters = new HashMap();

_formParameters = new HashMap();

int nFileSizeMax = 100000000;

int nSizeThreshold = 500000;

String sTmpFolder = “”;

// make the file item factory

DiskFileItemFactory factory = new DiskFileItemFactory();

factory.setSizeThreshold(nSizeThreshold);

if (sTmpFolder.length() > 0) {

File fTmpFolder = new File(sTmpFolder);

factory.setRepository(fTmpFolder);

}

// make the file upload object

ServletFileUpload fileUpload = new ServletFileUpload();

fileUpload.setFileItemFactory(factory);

fileUpload.setFileSizeMax(nFileSizeMax);

// parse the parameters associated with the request

List items = fileUpload.parseRequest(request);

String[] aValues;

ArrayList lValues;

for(int i=0;i

FileItem item = (FileItem)items.get(i);

getLogger().finer(“FileItem=”+item);

if (item.isFormField()) {

String sName = item.getFieldName();

String sValue = item.getString();

if (_formParameters.containsKey(sName)) {

aValues = _formParameters.get(sName);

lValues = new ArrayList(Arrays.asList(aValues));

lValues.add(sValue);

aValues = lValues.toArray(new String[0]);

} else {

aValues = new String[1];

aValues[0] = sValue;

}

_formParameters.put(sName,aValues);

} else {

_fileParameters.put(item.getFieldName(),item);

request.setAttribute(item.getFieldName(),item);

}

}

}

開發者ID:GeoinformationSystems,項目名稱:GeoprocessingAppstore,代碼行數:57,

注:本文中的org.apache.commons.fileupload.servlet.ServletFileUpload.setFileSizeMax方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

今天的文章java setmaxfilesize,Java ServletFileUpload.setFileSizeMax方法代碼示例分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/13352.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注