Example usage for org.apache.commons.fileupload DiskFileUpload DiskFileUpload

List of usage examples for org.apache.commons.fileupload DiskFileUpload DiskFileUpload

Introduction

In this page you can find the example usage for org.apache.commons.fileupload DiskFileUpload DiskFileUpload.

Prototype

public DiskFileUpload(DefaultFileItemFactory fileItemFactory) 

Source Link

Document

Constructs an instance of this class which uses the supplied factory to create FileItem instances.

Usage

From source file:com.w4t.engine.requests.FileUploadRequest.java

public FileUploadRequest(final HttpServletRequest request) throws ServletException {
    super(request);
    IConfiguration configuration = ConfigurationReader.getConfiguration();
    IFileUpload fileUpload = configuration.getFileUpload();
    UploadRequestFileItemFactory factory = new UploadRequestFileItemFactory();
    DiskFileUpload upload = new DiskFileUpload(factory);
    upload.setSizeThreshold(fileUpload.getMaxMemorySize());
    upload.setSizeMax(fileUpload.getMaxMemorySize());
    upload.setRepositoryPath(FileUploadRequest.SYSTEM_TEMP_DIR);
    try {/*from  w ww  . ja v  a2s .com*/
        List items = upload.parseRequest(request);
        Iterator iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            parameters.put(item.getFieldName(), item);
        }

    } catch (FileUploadException e) {
        throw new ServletExceptionAdapter(e);
    }
}

From source file:com.globalsight.everest.webapp.pagehandler.tasks.TaskDetailHandler.java

private void dtpUpload(HttpServletRequest p_request) throws EnvoyServletException {
    String uploadFileName = this.getFullTargetFilePath(p_request);

    try {/*from  w ww. j av a  2 s . c om*/
        DefaultFileItemFactory factory = new DefaultFileItemFactory();

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

        List items = upload.parseRequest(p_request);
        Iterator iter = items.iterator();
        if (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            File uploadDir = new File(this.getTargetFilePath(p_request));
            if (!uploadDir.isDirectory()) {
                uploadDir.mkdir();
            }
            File uploadFile = new File(uploadFileName);
            item.write(uploadFile);
        }
    } catch (FileUploadException e) {
        throw new EnvoyServletException(e);
    } catch (Exception e) {
        throw new EnvoyServletException(e);
    }
}

From source file:org.jxstar.control.action.ActionHelper.java

/**
 * ?/*  w w  w .  j  a v  a  2s  .  co  m*/
 * @param request
 * @return
 */
private static Map<String, Object> parseMultiRequest(HttpServletRequest request) throws ActionException {
    //?
    DefaultFileItemFactory factory = new DefaultFileItemFactory();
    //?
    DiskFileUpload upload = new DiskFileUpload(factory);
    //????
    upload.setHeaderEncoding("utf-8");
    //?10M
    String maxSize = SystemVar.getValue("upload.file.maxsize", "10");
    upload.setSizeMax(1000 * 1000 * Integer.parseInt(maxSize));
    //?
    List<FileItem> items = null;
    try {
        items = upload.parseRequest(request);
    } catch (FileUploadException e) {
        _log.showError(e);
        throw new ActionException(JsMessage.getValue("fileaction.overmaxsize"), maxSize);
    }
    _log.showDebug("request item size=" + items.size());

    //
    Map<String, Object> requestMap = FactoryUtil.newMap();
    // ?
    Iterator<FileItem> iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = iter.next();
        if (item.isFormField()) {
            String key = item.getFieldName();
            //?????
            String value = "";
            try {
                value = item.getString("utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            if (key == null || key.length() == 0)
                continue;
            requestMap.put(key, value);
        } else {
            String key = item.getFieldName();
            requestMap.put(key, item);
            //??
            String fileName = item.getName();
            String contentType = item.getContentType();
            long fileSize = item.getSize();
            _log.showDebug(
                    "request filename=" + fileName + ";fileSize=" + fileSize + ";contentType=" + contentType);
        }
    }

    return requestMap;
}