當前位置: 首頁>>代碼示例>>Java>>正文


Java FileItem.get方法代碼示例

本文整理匯總了Java中org.apache.commons.fileupload.FileItem.get方法的典型用法代碼示例。如果您正苦於以下問題:Java FileItem.get方法的具體用法?Java FileItem.get怎麽用?Java FileItem.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.fileupload.FileItem的用法示例。


在下文中一共展示了FileItem.get方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: importProject

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
public void importProject(HttpServletRequest req, HttpServletResponse resp) throws Exception {
	DiskFileItemFactory factory = new DiskFileItemFactory();
	ServletContext servletContext = req.getSession().getServletContext();
	File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
	factory.setRepository(repository);
	ServletFileUpload upload = new ServletFileUpload(factory);
	InputStream inputStream=null;
	boolean overwriteProject=true;
	List<FileItem> items = upload.parseRequest(req);
	if(items.size()==0){
		throw new ServletException("Upload file is invalid.");
	}
	for(FileItem item:items){
		String name=item.getFieldName();
		if(name.equals("overwriteProject")){
			String overwriteProjectStr=new String(item.get());
			overwriteProject=Boolean.valueOf(overwriteProjectStr);
		}else if(name.equals("file")){
			inputStream=item.getInputStream();
		}
	}
	repositoryService.importXml(inputStream,overwriteProject);
	IOUtils.closeQuietly(inputStream);
	resp.sendRedirect(req.getContextPath()+"/urule/frame");
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:26,代碼來源:FrameServletHandler.java

示例2: FileData

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
FileData(FileItem item)
{
	this.fileName = item.getName();
	this.type = item.getContentType();
	this.data = item.get();
	
	if(fileName != null)
	{
		int i = fileName.lastIndexOf("/");
		if(i>0)
		{
			fileName = fileName.substring(i+1);
		}
		else
		{
			i = fileName.lastIndexOf("\\");
			if(i>0)
    		{
    			fileName = fileName.substring(i+1);
    		}
		}
	}
	
	this.item = item;
}
 
開發者ID:fancimage,項目名稱:tern,代碼行數:26,代碼來源:FileData.java

示例3: handleRequestInternal

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.POST)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {

    String username = securityService.getCurrentUsername(request);

    // Check that we have a file upload request.
    if (!ServletFileUpload.isMultipartContent(request)) {
        throw new Exception("Illegal request.");
    }

    Map<String, Object> map = new HashMap<String, Object>();
    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    List<?> items = upload.parseRequest(request);

    // Look for file items.
    for (Object o : items) {
        FileItem item = (FileItem) o;

        if (!item.isFormField()) {
            String fileName = item.getName();
            byte[] data = item.get();

            if (StringUtils.isNotBlank(fileName) && data.length > 0) {
                createAvatar(fileName, data, username, map);
            } else {
                map.put("error", new Exception("Missing file."));
                LOG.warn("Failed to upload personal image. No file specified.");
            }
            break;
        }
    }

    map.put("username", username);
    map.put("avatar", settingsService.getCustomAvatar(username));
    return new ModelAndView("avatarUploadResult","model",map);
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:38,代碼來源:AvatarUploadController.java

示例4: getMultipartFormParametersMap

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
private Map<String, Part> getMultipartFormParametersMap() {
    if (!ServletFileUpload.isMultipartContent(this)) { // isMultipartContent also checks the content type
        return new HashMap<>();
    }

    Map<String, Part> output = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

    ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
    try {
        List<FileItem> items = upload.parseRequest(this);
        for (FileItem item : items) {
            AwsProxyRequestPart newPart = new AwsProxyRequestPart(item.get());
            newPart.setName(item.getName());
            newPart.setSubmittedFileName(item.getFieldName());
            newPart.setContentType(item.getContentType());
            newPart.setSize(item.getSize());

            Iterator<String> headerNamesIterator = item.getHeaders().getHeaderNames();
            while (headerNamesIterator.hasNext()) {
                String headerName = headerNamesIterator.next();
                Iterator<String> headerValuesIterator = item.getHeaders().getHeaders(headerName);
                while (headerValuesIterator.hasNext()) {
                    newPart.addHeader(headerName, headerValuesIterator.next());
                }
            }

            output.put(item.getFieldName(), newPart);
        }
    } catch (FileUploadException e) {
        log.error("Could not read multipart upload file", e);
    }
    return output;
}
 
開發者ID:awslabs,項目名稱:aws-serverless-java-container,代碼行數:34,代碼來源:AwsProxyHttpServletRequest.java

示例5: handleRequestInternal

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

    String username = securityService.getCurrentUsername(request);

    // Check that we have a file upload request.
    if (!ServletFileUpload.isMultipartContent(request)) {
        throw new Exception("Illegal request.");
    }

    Map<String, Object> map = new HashMap<String, Object>();
    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    List<?> items = upload.parseRequest(request);

    // Look for file items.
    for (Object o : items) {
        FileItem item = (FileItem) o;

        if (!item.isFormField()) {
            String fileName = item.getName();
            byte[] data = item.get();

            if (StringUtils.isNotBlank(fileName) && data.length > 0) {
                createAvatar(fileName, data, username, map);
            } else {
                map.put("error", new Exception("Missing file."));
                LOG.warn("Failed to upload personal image. No file specified.");
            }
            break;
        }
    }

    map.put("username", username);
    map.put("avatar", settingsService.getCustomAvatar(username));
    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:40,代碼來源:AvatarUploadController.java

示例6: doPost

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    boolean isMultipart = ServletFileUpload.isMultipartContent(req);
    HttpSession session = req.getSession(false);
    Integer userId = (int)session.getAttribute("id_user");
    Integer orderId = (int)session.getAttribute("currentOrder");
    PrintWriter out = resp.getWriter();
    JsonObject jsonObject = new JsonObject();

    if(isMultipart && userId != -1 && orderId != -1){
        // Create a factory for disk-based file items
        DiskFileItemFactory factory = new DiskFileItemFactory();
        // Configure a repository (to ensure a secure temp location is used)
        ServletContext servletContext = this.getServletConfig().getServletContext();

        FileCleaningTracker tracker = FileCleanerCleanup.getFileCleaningTracker(servletContext);
        factory.setFileCleaningTracker(tracker);
        File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
        factory.setRepository(repository);

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);

        try {
            List<FileItem> items = upload.parseRequest(req);

            for (FileItem imageFile : items){
                byte[] imageByte = imageFile.get();
                Order order = new Order();
                order.setId(orderId);
                Image image = new Image();
                image.setDataimage(imageByte);
                image.setOrder(order);
                new ImageDBManager().create(image);
            }
            jsonObject.addProperty("success", true);

        } catch (FileUploadException e) {
            jsonObject.addProperty("success", false);
            e.printStackTrace();
        }
    } else {
        jsonObject.addProperty("success", false);
    }

    out.append(jsonObject.toString());
    out.flush();


}
 
開發者ID:SergeyZhernovoy,項目名稱:Java-education,代碼行數:52,代碼來源:ImageServlet.java


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