/** * Upload status update callback * * @param bytesUploaded * @param total */ protected void onUploadUpdate(int bytesUploaded, int total) { HttpServletRequest request = getContainerRequest(); UploadInfo info = getUploadInfo(request, upload); if (info == null) { throw new IllegalStateException( "could not find UploadInfo object in session which should have been set when uploaded started"); } info.setBytesUploaded(bytesUploaded); setUploadInfo(request, upload, info); }
/** * Creates multipart web request from this request. * * @param maxSize * max allowed size of request * @param upload * upload identifier for {@link UploadInfo} * @return multipart request * @throws FileUploadException */ public MultipartServletWebRequest newMultipartWebRequest(Bytes maxSize, String upload) throws FileUploadException { return new MultipartServletWebRequestImpl(getContainerRequest(), filterPrefix, maxSize, upload); }
/** * Upload completed callback */ protected void onUploadCompleted() { clearUploadInfo(getContainerRequest(), upload); }
/** * Upload start callback * * @param totalBytes */ protected void onUploadStarted(int totalBytes) { UploadInfo info = new UploadInfo(totalBytes); setUploadInfo(getContainerRequest(), upload, info); }
@Override public void parseFileParts() throws FileUploadException HttpServletRequest request = getContainerRequest(); FileUploadBase fileUpload = newFileUpload(encoding); if (wantUploadProgressUpdates()) totalBytes = request.getContentLength(); onUploadStarted(totalBytes); try onUploadCompleted(); items = readServlet3Parts(request); addParameter(item.getFieldName(), value);
/** * @param attributes * @return status string with progress data that will feed the progressbar.js variables on * browser to update the progress bar */ private String getStatus(final Attributes attributes) { final String upload = attributes.getParameters().get(UPLOAD_PARAMETER).toString(); final HttpServletRequest req = (HttpServletRequest)attributes.getRequest() .getContainerRequest(); UploadInfo info = MultipartServletWebRequestImpl.getUploadInfo(req, upload); String status; if ((info == null) || (info.getTotalBytes() < 1)) { status = "100|"; } else { status = info.getPercentageComplete() + "|" + new StringResourceModel(RESOURCE_STATUS, (Component)null, Model.of(info)).getString(); } return status; }
/** * Factory method for creating new instances of FileUploadBase * * @param encoding * The encoding to use while reading the data * @return A new instance of FileUploadBase */ protected FileUploadBase newFileUpload(String encoding) { // Configure the factory here, if desired. ServletFileUpload fileUpload = new ServletFileUpload(fileItemFactory); // set encoding specifically when we found it if (encoding != null) { fileUpload.setHeaderEncoding(encoding); } fileUpload.setSizeMax(getMaxSize().bytes()); Bytes fileMaxSize = getFileMaxSize(); if (fileMaxSize != null) { fileUpload.setFileSizeMax(fileMaxSize.bytes()); } return fileUpload; }
@Override public MultipartServletWebRequest newMultipartWebRequest(Bytes maxSize, String upload) throws FileUploadException { // FIXME mgrigorov: Why these checks are made here ?! // Why they are not done also at org.apache.wicket.protocol.http.servlet.MultipartServletWebRequestImpl.newMultipartWebRequest(org.apache.wicket.util.lang.Bytes, java.lang.String, org.apache.wicket.util.upload.FileItemFactory)() ? // Why there is no check that the summary of all files' sizes is less than the set maxSize ? // Setting a breakpoint here never breaks with the standard upload examples. Bytes fileMaxSize = getFileMaxSize(); for (Map.Entry<String, List<FileItem>> entry : files.entrySet()) { List<FileItem> fileItems = entry.getValue(); for (FileItem fileItem : fileItems) { if (fileMaxSize != null && fileItem.getSize() > fileMaxSize.bytes()) { String fieldName = entry.getKey(); FileUploadException fslex = new FileUploadBase.FileSizeLimitExceededException("The field '" + fieldName + "' exceeds its maximum permitted size of '" + maxSize + "' characters.", fileItem.getSize(), fileMaxSize.bytes()); throw fslex; } } } return this; }
@Override public void parseFileParts() throws FileUploadException HttpServletRequest request = getContainerRequest(); FileUploadBase fileUpload = newFileUpload(encoding); if (wantUploadProgressUpdates()) totalBytes = request.getContentLength(); onUploadStarted(totalBytes); try onUploadCompleted(); items = readServlet3Parts(request); addParameter(item.getFieldName(), value);
/** * @param attributes * @return status string with progress data that will feed the progressbar.js variables on * browser to update the progress bar */ private String getStatus(final Attributes attributes) { final String upload = attributes.getParameters().get(UPLOAD_PARAMETER).toString(); final HttpServletRequest req = (HttpServletRequest)attributes.getRequest() .getContainerRequest(); UploadInfo info = MultipartServletWebRequestImpl.getUploadInfo(req, upload); String status; if ((info == null) || (info.getTotalBytes() < 1)) { status = "100|"; } else { status = info.getPercentageComplete() + "|" + new StringResourceModel(RESOURCE_STATUS, (Component)null, Model.of(info)).getString(); } return status; }
/** * Upload start callback * * @param totalBytes */ protected void onUploadStarted(int totalBytes) { UploadInfo info = new UploadInfo(totalBytes); setUploadInfo(getContainerRequest(), upload, info); }
/** * Factory method for creating new instances of FileUploadBase * * @param encoding * The encoding to use while reading the data * @return A new instance of FileUploadBase */ protected FileUploadBase newFileUpload(String encoding) { // Configure the factory here, if desired. ServletFileUpload fileUpload = new ServletFileUpload(fileItemFactory); // set encoding specifically when we found it if (encoding != null) { fileUpload.setHeaderEncoding(encoding); } fileUpload.setSizeMax(getMaxSize().bytes()); Bytes fileMaxSize = getFileMaxSize(); if (fileMaxSize != null) { fileUpload.setFileSizeMax(fileMaxSize.bytes()); } return fileUpload; }
@Override public MultipartServletWebRequest newMultipartWebRequest(Bytes maxSize, String upload) throws FileUploadException { // FIXME mgrigorov: Why these checks are made here ?! // Why they are not done also at org.apache.wicket.protocol.http.servlet.MultipartServletWebRequestImpl.newMultipartWebRequest(org.apache.wicket.util.lang.Bytes, java.lang.String, org.apache.wicket.util.upload.FileItemFactory)() ? // Why there is no check that the summary of all files' sizes is less than the set maxSize ? // Setting a breakpoint here never breaks with the standard upload examples. Bytes fileMaxSize = getFileMaxSize(); for (Map.Entry<String, List<FileItem>> entry : files.entrySet()) { List<FileItem> fileItems = entry.getValue(); for (FileItem fileItem : fileItems) { if (fileMaxSize != null && fileItem.getSize() > fileMaxSize.bytes()) { String fieldName = entry.getKey(); FileUploadException fslex = new FileUploadBase.FileSizeLimitExceededException("The field '" + fieldName + "' exceeds its maximum permitted size of '" + maxSize + "' characters.", fileItem.getSize(), fileMaxSize.bytes()); throw fslex; } } } return this; }
/** * Upload status update callback * * @param bytesUploaded * @param total */ protected void onUploadUpdate(int bytesUploaded, int total) { HttpServletRequest request = getContainerRequest(); UploadInfo info = getUploadInfo(request, upload); if (info == null) { throw new IllegalStateException( "could not find UploadInfo object in session which should have been set when uploaded started"); } info.setBytesUploaded(bytesUploaded); setUploadInfo(request, upload, info); }
/** * @param attributes * @return status string with progress data that will feed the progressbar.js variables on * browser to update the progress bar */ private String getStatus(final Attributes attributes) { final String upload = attributes.getParameters().get(UPLOAD_PARAMETER).toString(); final HttpServletRequest req = (HttpServletRequest)attributes.getRequest() .getContainerRequest(); UploadInfo info = MultipartServletWebRequestImpl.getUploadInfo(req, upload); String status; if ((info == null) || (info.getTotalBytes() < 1)) { status = "100|"; } else { status = info.getPercentageComplete() + "|" + new StringResourceModel(RESOURCE_STATUS, (Component)null, Model.of(info)).getString(); } return status; }
/** * Upload completed callback */ protected void onUploadCompleted() { clearUploadInfo(getContainerRequest(), upload); }
/** * Creates multipart web request from this request. * * @param maxSize * max allowed size of request * @param upload * upload identifier for {@link UploadInfo} * @return multipart request * @throws FileUploadException */ public MultipartServletWebRequest newMultipartWebRequest(Bytes maxSize, String upload) throws FileUploadException { return new MultipartServletWebRequestImpl(getContainerRequest(), filterPrefix, maxSize, upload); }
/** * Creates multipart web request from this request. * * @param maxSize * max allowed size of request * @param upload * upload identifier for {@link UploadInfo} * @param factory * @return multipart request * @throws FileUploadException */ public MultipartServletWebRequest newMultipartWebRequest(Bytes maxSize, String upload, FileItemFactory factory) throws FileUploadException { return new MultipartServletWebRequestImpl(getContainerRequest(), filterPrefix, maxSize, upload, factory); }
/** * Creates multipart web request from this request. * * @param maxSize * max allowed size of request * @param upload * upload identifier for {@link UploadInfo} * @param factory * @return multipart request * @throws FileUploadException */ public MultipartServletWebRequest newMultipartWebRequest(Bytes maxSize, String upload, FileItemFactory factory) throws FileUploadException { return new MultipartServletWebRequestImpl(getContainerRequest(), filterPrefix, maxSize, upload, factory); }