The forms elements were beeing wrapped in the wrong way! I changed the processFileItems to this:
protected HttpServletRequest processFileItems(HttpServletRequest request, FileItemIterator fileItems) { if (uploadException == null && (fileItems == null)) { return request; } ParametersServletRequestWrapper wrapper = newParametersServletRequestWrapper( request); String charset = request.getCharacterEncoding(); try { for (FileItemIterator it = fileItems; it.hasNext();) { FileItemStream item; item = it.next(); final byte[] buffer = IOUtils.toByteArray(item.openStream()); logger.debug("########" + item.getName()); logger.debug("########" + item.getFieldName()); if (item.isFormField()) { wrapper.addParameter(item.getFieldName(), new String(buffer, charset)); } else { wrapper.addParameter(item.getFieldName(), item.getName()); wrapper.addParameter(item.getFieldName(), item.getName()); addUploadedFile(item.getFieldName(), newByteArrayInputStream(buffer)); } } } catch (FileUploadException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return wrapper; } Everything works again! On 16 April 2011 15:31, Fernando Benjamin <fernandobenja...@gmail.com>wrote: > Hi All, > > Thank you for all your answers, I've read the form specification ( > http://www.w3.org/TR/html4/interact/forms.html) > and then I looked into Tapestry's upload component! I understand this > component and forms much better now. > Again, my goal is: An upload form that uploads files and stores it in > GAE(BLOB) with Tapestry5! > > > I've made my own ServletFilter, with an own MultipartDecodeImpl and a > request which decodes the form before passing it to the page Class. > I've pretty much used a lot of aspects of the Upload component. > But instead of making a new component, I've handled everything in my own > MultpartDecoder and filter! > > The problem right now is, that I get an exception: after passing the > handler to the chain! > java.util.zip.ZipException: Not in GZIP format > > > > It looks like I've forgot to zip something? But I don't know what, why and > where? > > > > > ################################### This is My RequestFilter > > public class MyProjectUploadFilter implements HttpServletRequestFilter { > > @Inject > > private Logger logger; > > > > private final MyProjectMultipartDecoder decoder; > > private final String method = "post"; > > /** > > * Part of HTTP content type header. > > */ > > public static final String MULTIPART = "multipart/"; > > > public MyProjectUploadFilter(MyProjectMultipartDecoder decoder) { > > this.decoder = decoder; > > } > > > @Override > > public boolean service(HttpServletRequest request, HttpServletResponse > response, HttpServletRequestHandler handler) throws IOException { > > if (method.equalsIgnoreCase(request.getMethod()) ) { > > HttpServletRequest newRequest = ServletFileUpload.isMultipartContent( > request) ? decoder.decode(request) : request; > > return handler.service(newRequest, response); > > } > > return handler.service(request, response); > > } > > > } > > > ################# This is my MultpartdecoderImpl > > > public class MyProjectMultipartDecoderImpl implements > MyProjectMultipartDecoder { > > private final Map<String, Blob> uploads = CollectionFactory.newMap(); > > private final Logger logger; > > private final FileItemFactory fileItemFactory; > > // > > // private final long maxRequestSize; > > // > > private final long maxFileSize = 250000; > > > private final String requestEncoding; > > > private FileUploadException uploadException; > > > public MyProjectMultipartDecoderImpl(Logger log, FileItemFactory > fileItemFactory) { > > this.logger = log; > > this.fileItemFactory = fileItemFactory; > > this.requestEncoding = "UTF-8"; > > } > > > @Override > > public HttpServletRequest decode(HttpServletRequest request) { > > try { > > request.setCharacterEncoding(requestEncoding); > > } catch (UnsupportedEncodingException ex) { > > throw new RuntimeException(ex); > > } > > FileItemIterator fileItems = parseRequest(request); > > > return processFileItems(request, fileItems); > > } > > > @Override > > public Blob getFileUpload(String parameterName) { > > return uploads.get(parameterName); > > } > > > @Override > > public FileUploadException getUploadException() { > > return uploadException; > > } > > > > > protected FileItemIterator parseRequest(HttpServletRequest request) { > > > try { > > return createFileUpload().getItemIterator(request); > > } catch (FileUploadException e) { > > // TODO Auto-generated catch block > > e.printStackTrace(); > > } catch (IOException e) { > > // TODO Auto-generated catch block > > e.printStackTrace(); > > } > > return null; > > } > > > protected ServletFileUpload createFileUpload() { > > ServletFileUpload upload = new ServletFileUpload(fileItemFactory); > > > // // set maximum file upload size > > // upload.setSizeMax(maxRequestSize); > > upload.setFileSizeMax(maxFileSize); > > > return upload; > > } > > > protected HttpServletRequest processFileItems(HttpServletRequest request, > FileItemIterator fileItems) { > > if (uploadException == null && (fileItems == null)) { > > return request; > > } > > ParametersServletRequestWrapper wrapper = new > ParametersServletRequestWrapper(request); > > > try { > > for (FileItemIterator it = fileItems; it.hasNext();) { > > FileItemStream item; > > item = it.next(); > > if (item.isFormField()) { > > wrapper.addParameter(item.getFieldName(), item.getFieldName()); > > } else { > > logger.debug("########" + item.getName()); > > logger.debug("########" + item.getFieldName()); > > wrapper.addParameter(item.getFieldName(), item.getName()); > > > > } > > } > > } catch (FileUploadException e) { > > e.printStackTrace(); > > } catch (IOException e) { > > e.printStackTrace(); > > } > > > return wrapper; > > } > > > protected void addUploadedFile(String name, Blob file) { > > uploads.put(name, file); > > } > > } > > > ################################ THIS IS MY FORM > > <html t:type="layout" > > title="${message:title}" > > xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" > > xmlns:p="tapestry:parameter"> > > <p>Post a new product:</p> > > <t:form t:id="upload" method="POST" > > > <t:errors/> > > <t:beaneditor t:id="product" object="product" /> > > <br/><br/> > > <input type="file" id="ga" name="file"/> > > > <br/><br/> > > <input t:type="submit" t:id="button" t:value="message:button-label" > /> > > > > </t:form> > > </html> > > > > > #################################### THIS IS MY EXCEPTION > > - > - Triggering event 'action' on personal/AddProduct:upload > - org.apache.tapestry5.runtime.ComponentEventException > java.util.zip.ZipException: Not in GZIP format > > > On 9 April 2011 16:31, Taha Hafeez <tawus.tapes...@gmail.com> wrote: > >> >> If you can use an ajax file uploader then you can modify this to meet your >> needs >> >> >> http://tapestry.1045711.n5.nabble.com/Tapestry-FileUploader-Integration-td4268987.html >> >> regards >> Taha >> >> -- >> View this message in context: >> http://tapestry.1045711.n5.nabble.com/Setting-contenttype-of-T5-form-tp4270175p4292978.html >> Sent from the Tapestry - User mailing list archive at Nabble.com. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> >> >