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


Java DiskFileUpload类代码示例

本文整理汇总了Java中org.apache.commons.fileupload.DiskFileUpload的典型用法代码示例。如果您正苦于以下问题:Java DiskFileUpload类的具体用法?Java DiskFileUpload怎么用?Java DiskFileUpload使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: parseRequest

import org.apache.commons.fileupload.DiskFileUpload; //导入依赖的package包/类
public static void parseRequest(HttpServletRequest request, HashMap<String, String> arrParam, ArrayList<FileItem> fi, boolean fileUpload) throws ServiceException {
    DiskFileUpload fu = new DiskFileUpload();
    FileItem fi1 = null;
    List fileItems = null;
    try {
        fileItems = fu.parseRequest(request);
    } catch (FileUploadException e) {
        throw ServiceException.FAILURE("Admin.createUser", e);
    }
    for (Iterator k = fileItems.iterator(); k.hasNext();) {
        fi1 = (FileItem) k.next();
        if (fi1.isFormField()) {
            arrParam.put(fi1.getFieldName(), fi1.getString());
        } else {
            try {
                String fileName = new String(fi1.getName().getBytes(), "UTF8");
                if (fi1.getSize() != 0) {
                    fi.add(fi1);
                    fileUpload = true;
                }
            } catch (UnsupportedEncodingException ex) {
            }
        }
    }
}
 
开发者ID:mobilipia,项目名称:Deskera-HRMS,代码行数:26,代码来源:fileUploader.java

示例2: getHashtable

import org.apache.commons.fileupload.DiskFileUpload; //导入依赖的package包/类
public Hashtable getHashtable(HttpServletRequest request)
        throws FileUploadException, IOException {
    Hashtable ht = new Hashtable();
    DiskFileUpload upload = new DiskFileUpload();
    List fileItems = upload.parseRequest(request);
    Iterator iter = fileItems.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();
        if (item.isFormField()) {
            ht.put(item.getFieldName(), item.getString());
        } else {
            if (item.getName().equals("")) {
                //ht.put(item.getFieldName(), null);
            } else if (item.getSize() == 0) {
                //ht.put(item.getFieldName(), null);
            } else {
                ht.put(item.getFieldName(), item.getInputStream());
            }
        }
    }
    return ht;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:23,代码来源:PartnershipPageletAdaptor.java

示例3: getHashtable

import org.apache.commons.fileupload.DiskFileUpload; //导入依赖的package包/类
public Hashtable getHashtable(HttpServletRequest request)
    throws FileUploadException, IOException {
	Hashtable ht = new Hashtable();
	DiskFileUpload upload = new DiskFileUpload();
	List fileItems = upload.parseRequest(request);
	Iterator iter = fileItems.iterator();
	while (iter.hasNext()) {
	    FileItem item = (FileItem) iter.next();
	    if (item.isFormField()) {
	        ht.put(item.getFieldName(), item.getString());
	    } else {
	        if (item.getName().equals("")) {
	            //ht.put(item.getFieldName(), null);
	        } else if (item.getSize() == 0) {
	            //ht.put(item.getFieldName(), null);
	        } else {
	            ht.put(item.getFieldName(), item.getInputStream());
	        }
	    }
	}
	return ht;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:23,代码来源:PartnershipPageletAdaptor.java

示例4: uploadFiles

import org.apache.commons.fileupload.DiskFileUpload; //导入依赖的package包/类
private List uploadFiles(HttpServletRequest req) throws FileUploadException 
{
  DiskFileUpload upload = new DiskFileUpload();

  /*try 
  {
    upload.setSizeThreshold(res.getInteger("file.upload.size.threshold"));
  } 
  catch (MissingResourceException e)
  {
    // use defaults
  }*/

  try 
  {
    upload.setSizeMax(MaxFileSize);
  } 
  catch (MissingResourceException e) 
  {
    // use defaults
  }

  /*try 
  {
    upload.setRepositoryPath(res.getString("file.upload.repository"));
  } 
  catch (MissingResourceException e) 
  {
    // use defaults
  }*/

  List all = new DiskFileUpload().parseRequest(req);
  return all;
}
 
开发者ID:fancimage,项目名称:tern,代码行数:35,代码来源:MultiPartEnabledRequest.java

示例5: getUploadItems

import org.apache.commons.fileupload.DiskFileUpload; //导入依赖的package包/类
/**
    * Given the current servlet request and the name of a temporary directory, get a list of all the uploaded items
    * from a multipart form. This includes any uploaded files and the "normal" input fields on the form.
    *
    * @param request
    *            - current servlet request
    * @param useLargeFileSize
    *            - use the large file size. If not true, use the standard file size.
    * @param tempDirName
    *            - the name of the directory into which temporary files can be written
    * @return List of items, of type FileItem
    */
   @SuppressWarnings("unchecked")
   public static List<FileItem> getUploadItems(HttpServletRequest request, boolean useLargeFileSize,
    String tempDirNameInput) throws FileUploadException, Exception {

int max_size = UploadFileUtil.DEFAULT_MAX_SIZE;
int max_memory_size;
String tempDirName = null;

int tempInt = -1;

if (useLargeFileSize) {
    tempInt = Configuration.getAsInt(ConfigurationKeys.UPLOAD_FILE_LARGE_MAX_SIZE);
    if (tempInt != -1) {
	max_size = tempInt;
    } else {
	UploadFileUtil.log.warn(
		"Default Large Max Size for file upload missing, using " + UploadFileUtil.DEFAULT_MAX_SIZE);
    }
} else {
    tempInt = Configuration.getAsInt(ConfigurationKeys.UPLOAD_FILE_MAX_SIZE);
    if (tempInt != -1) {
	max_size = tempInt;
    } else {
	UploadFileUtil.log
		.warn("Default Max Size for file upload missing, using " + UploadFileUtil.DEFAULT_MAX_SIZE);
    }
}

tempInt = Configuration.getAsInt(ConfigurationKeys.UPLOAD_FILE_MAX_MEMORY_SIZE);
if (tempInt != -1) {
    max_memory_size = tempInt;
} else {
    UploadFileUtil.log.warn(
	    "Default Max Memory Size for file upload missing, using " + UploadFileUtil.DEFAULT_MEMORY_SIZE);
    max_memory_size = UploadFileUtil.DEFAULT_MEMORY_SIZE;
}

if (tempDirNameInput != null) {
    tempDirName = tempDirNameInput;
} else {
    tempDirName = Configuration.get(ConfigurationKeys.LAMS_TEMP_DIR);
    if (tempDirName == null) {
	UploadFileUtil.log.warn("Default Temporary Directory missing, using null");
    }
}
// would be nice to only do this once! never mind.
if (tempDirName != null) {
    File dir = new File(tempDirName);
    if (!dir.exists()) {
	dir.mkdirs();
    }
}

// Create a new file upload handler
DiskFileUpload upload = new DiskFileUpload();

// Set upload parameters
upload.setSizeMax(max_size);
upload.setSizeThreshold(max_memory_size);
upload.setRepositoryPath(tempDirName);

// Parse the request
List<FileItem> items = upload.parseRequest(request);
return items;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:78,代码来源:UploadFileUtil.java

示例6: execute

import org.apache.commons.fileupload.DiskFileUpload; //导入依赖的package包/类
@SuppressWarnings("unchecked")
   @Override
   public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
// cumberstone way of extracting POSTed form with a file
DiskFileUpload formParser = new DiskFileUpload();
formParser.setRepositoryPath(Configuration.get(ConfigurationKeys.LAMS_TEMP_DIR));
List<FileItem> formFields = formParser.parseRequest(request);

String returnURL = null;
String limitTypeParam = null;
InputStream uploadedFileStream = null;
String packageName = null;
for (FileItem formField : formFields) {
    String fieldName = formField.getFieldName();
    if ("returnURL".equals(fieldName)) {
	// this can be empty; if so, another method of delivering results is used
	returnURL = formField.getString();
    } else if ("limitType".equals(fieldName)) {
	limitTypeParam = formField.getString();
    } else if ("file".equals(fieldName) && !StringUtils.isBlank(formField.getName())) {
	packageName = formField.getName().toLowerCase();
	uploadedFileStream = formField.getInputStream();
    }
}

// this parameter is not really used at the moment
request.setAttribute("returnURL", returnURL);

// show only chosen types of questions
request.setAttribute("limitType", limitTypeParam);

// user did not choose a file
if ((uploadedFileStream == null) || !(packageName.endsWith(".zip") || packageName.endsWith(".xml"))) {
    ActionMessages errors = new ActionMessages();
    errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("label.questions.file.missing"));
    request.setAttribute(Globals.ERROR_KEY, errors);
    return mapping.findForward("questionFile");
}

Set<String> limitType = null;
if (!StringUtils.isBlank(limitTypeParam)) {
    limitType = new TreeSet<String>();
    // comma delimited acceptable question types, for example "mc,fb"
    Collections.addAll(limitType, limitTypeParam.split(","));
}

Question[] questions = packageName.endsWith(".xml")
	? QuestionParser.parseQTIFile(uploadedFileStream, null, limitType)
	: QuestionParser.parseQTIPackage(uploadedFileStream, limitType);
request.setAttribute("questions", questions);

return mapping.findForward("questionChoice");
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:55,代码来源:QuestionsAction.java

示例7: doPost

import org.apache.commons.fileupload.DiskFileUpload; //导入依赖的package包/类
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        log("Recepci� formulari");        
        log("Charset: " + request.getCharacterEncoding());

        String xmlInicial = "";
        String xmlFinal = "";
        if (FileUpload.isMultipartContent(request)) {
            try {
                DiskFileUpload fileUpload = new DiskFileUpload();
                List fileItems = fileUpload.parseRequest(request);

                for (int i = 0; i < fileItems.size(); i++) {
                    FileItem fileItem = (FileItem) fileItems.get(i);
                    if (fileItem.getFieldName().equals("xmlInicial")) {
                        xmlInicial = fileItem.getString();
                    }

                    if (fileItem.getFieldName().equals("xmlFinal")) {
                        xmlFinal = fileItem.getString();
                    }
                }
            } catch (FileUploadException e) {
                throw new UnavailableException("Error uploading", 1);
            }
        } else {
            xmlInicial = request.getParameter("xmlInicial");
            xmlFinal = request.getParameter("xmlFinal");
        }

        log("XML Inicial: " + xmlInicial);
        log("XML Final: " + xmlFinal);

        byte[] bytes = String.valueOf(System.currentTimeMillis()).getBytes();
        byte[] encBytes = Base64.encodeBase64(bytes);
        String token = new String(encBytes, "UTF-8");

        getServletContext().setAttribute("[email protected]" + token, xmlInicial);
        getServletContext().setAttribute("[email protected]" + token, xmlFinal);

        log("Tornant token: " + token);

        response.reset();
        response.setContentLength(encBytes.length);
        response.setContentType("text/plain; charset=UTF-8");
        response.getOutputStream().write(encBytes);
        response.flushBuffer();
    }
 
开发者ID:GovernIB,项目名称:sistra,代码行数:49,代码来源:RecepcioFormServlet.java

示例8: doPost

import org.apache.commons.fileupload.DiskFileUpload; //导入依赖的package包/类
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        log("Iniciar tramitaci�");

        String xmlData = "";
        String xmlConfig = "";

        if (FileUpload.isMultipartContent(request)) {
            try {
                DiskFileUpload fileUpload = new DiskFileUpload();
                List fileItems = fileUpload.parseRequest(request);

                for (int i = 0; i < fileItems.size(); i++) {
                    FileItem fileItem = (FileItem) fileItems.get(i);
                    if (fileItem.getFieldName().equals("xmlData")) {
                        xmlData = fileItem.getString();
                    }

                    if (fileItem.getFieldName().equals("xmlConfig")) {
                        xmlConfig = fileItem.getString();
                    }
                }
            } catch (FileUploadException e) {
                throw new UnavailableException("Error uploading", 1);
            }
        } else {
            xmlData = request.getParameter("xmlData");
            xmlConfig = request.getParameter("xmlConfig");
        }

        log("XML Data: " + xmlData);
        log("XML Config: " + xmlConfig);

        log("Enviant dades a: " + urlTramitacio);

        String token = iniciarTramite(xmlData, xmlConfig);

        if (token == null) {
            log("Token �s null");
        } else {
            log("Token: " + token);

            StringBuffer url = new StringBuffer(urlRedireccio);
            url.append(urlRedireccio.indexOf('?') == -1 ? '?' : '&');
            url.append(tokenName);
            url.append('=');
            url.append(token);

            log("Redireccionant a: " + url.toString());
            response.sendRedirect(response.encodeRedirectURL(url.toString()));
        }
    }
 
开发者ID:GovernIB,项目名称:sistra,代码行数:53,代码来源:IniciFormServlet.java

示例9: getCenterSource

import org.apache.commons.fileupload.DiskFileUpload; //导入依赖的package包/类
protected Source getCenterSource(HttpServletRequest request) {

        PropertyTree dom = new PropertyTree();
        dom.setProperty("/partnership", "");

        boolean isMultipart = FileUpload.isMultipartContent(request);

        if (isMultipart) {
            DiskFileUpload upload = new DiskFileUpload();
            try {
                FileItem realFileItem = null;
                boolean hasFileField = false;
                List fileItems = upload.parseRequest(request);

                Iterator iter = fileItems.iterator();
                while (iter.hasNext()) {
                    FileItem item = (FileItem) iter.next();

                    if (item.isFormField()) {
                        if (item.getFieldName().equals("party_name")) {
                            selectedPartyName = item.getString();
                        }
                    } else {
                        hasFileField = true;

                        if (item.getName().equals("")) {
                            request.setAttribute(ATTR_MESSAGE,
                                    "No file specified");
                        } else if (item.getSize() == 0) {
                            request.setAttribute(ATTR_MESSAGE,
                                    "The file is no content");
                        } else if (!item.getContentType().equalsIgnoreCase(
                                "text/xml")) {
                            request.setAttribute(ATTR_MESSAGE,
                                    "It is not a xml file");
                        } else {
                            realFileItem = item;
                        }
                    }
                }

                if (!hasFileField) {
                    request.setAttribute(ATTR_MESSAGE,
                            "There is no file field in the request paramters");
                }

                if (selectedPartyName.equalsIgnoreCase("")) {
                    request
                            .setAttribute(ATTR_MESSAGE,
                                    "There is no party name field in the request paramters");
                } else {
                    X_ATTR_PARTY_NAME = "[@" + X_TP_NAMESPACE + "partyName='"
                            + selectedPartyName + "']";
                }

                if (realFileItem != null
                        && !selectedPartyName.equalsIgnoreCase("")) {
                    String errorMessage = processUploadedXml(dom, realFileItem);
                    if (errorMessage != null) {
                        request.setAttribute(ATTR_MESSAGE, errorMessage);
                    }

                }
            } catch (Exception e) {
                EbmsProcessor.core.log.error(
                        "Exception throw when upload the file", e);
                request.setAttribute(ATTR_MESSAGE,
                        "Exception throw when upload the file");
            }
        }

        return dom.getSource();
    }
 
开发者ID:cecid,项目名称:hermes,代码行数:74,代码来源:AgreementUploadPageletAdaptor.java

示例10: doFilter

import org.apache.commons.fileupload.DiskFileUpload; //导入依赖的package包/类
/**
 * Filter the current request. If it is a multipart request, parse it and
 * wrap it before chaining to the next filter or servlet. Otherwise, pass
 * it on untouched.
 */
@Override
@SuppressWarnings("unchecked")
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
	throws IOException, ServletException
{
	if (!FileUploadBase.isMultipartContent(request))
	{
		chain.doFilter(request, response);
		return;
	}

	try
	{
		//FileItemFactory fact = new DiskFileItemFactory();
		//FileUpload upload = new ServletFileUpload(fact);
		DiskFileUpload upload = new DiskFileUpload();
		upload.setSizeMax(MAX_UPLOAD_BYTES);

		List<FileItem> items = upload.parseRequest(request);

		Map<String, String[]> params = new HashMap<String, String[]>();
		List<FileItem> files = new ArrayList<FileItem>(items.size());

		for (FileItem item: items)
		{
			if (item.isFormField())
			{
				// Add it to the array in the params, creating the array if necessary
				String[] array = params.get(item.getFieldName());
				if (array == null)
				{
					array = new String[] { item.getString() };
				}
				else
				{
					String[] newArray = new String[array.length + 1];
					System.arraycopy(array, 0, newArray, 0, array.length);
					newArray[newArray.length - 1] = item.getString();

					array = newArray;
				}

				params.put(item.getFieldName(), array);
			}
			else
				files.add(item);
		}

		request.setAttribute(ATTR_FILES, files);
		HttpServletRequest wrapped = new RequestWrapper(request, params);

		chain.doFilter(wrapped, response);
	}
	catch (FileUploadException ex)
	{
		// Just save the exception for later.
		request.setAttribute(ATTR_EXCEPTION, ex);

		chain.doFilter(request, response);
	}
}
 
开发者ID:voodoodyne,项目名称:subetha,代码行数:67,代码来源:FileUploadFilter.java


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