Example usage for org.apache.wicket.protocol.http.servlet ServletWebRequest newMultipartWebRequest

List of usage examples for org.apache.wicket.protocol.http.servlet ServletWebRequest newMultipartWebRequest

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http.servlet ServletWebRequest newMultipartWebRequest.

Prototype

public MultipartServletWebRequest newMultipartWebRequest(Bytes maxSize, String upload, FileItemFactory factory)
        throws FileUploadException 

Source Link

Document

Creates multipart web request from this request.

Usage

From source file:org.hippoecm.frontend.plugins.jquery.upload.behaviors.AjaxFileUploadBehavior.java

License:Apache License

/**
 * Create a multi-part request containing uploading files that supports disk caching.
 *
 * @param request/*w  w w.j ava 2 s. c  om*/
 * @return the multi-part request or exception thrown if there's any error.
 * @throws FileUploadException
 */
private MultipartServletWebRequest createMultipartWebRequest(final ServletWebRequest request)
        throws FileUploadException {
    DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(
            Application.get().getResourceSettings().getFileCleaner()) {
        @Override
        public FileItem createItem(String fieldName, String contentType, boolean isFormField, String fileName) {
            FileItem item = super.createItem(fieldName, contentType, isFormField, fileName);
            return new TemporaryFileItem(item);
        }
    };

    try {
        long contentLength = Long.valueOf(request.getHeader("Content-Length"));
        if (contentLength > 0) {
            return request.newMultipartWebRequest(Bytes.bytes(contentLength), container.getPage().getId(),
                    diskFileItemFactory);
        } else {
            throw new FileUploadException("Invalid file upload content length");
        }
    } catch (NumberFormatException e) {
        throw new FileUploadException("Invalid file upload content length", e);
    }
}