I've read several posts about this but everyon seems to be using
different code and different methods. I've tried several but none seem
to work. I must be missing some fundamental component.

I try to upload a file but even though the request arrives on server
side theres no file. The request is only 48 bytes and I can't figure
out why. If anyone can tell me what I'm doing wrong I'd greatly
appreciate it.

Client side:
           FormPanel form = new FormPanel();
            form.setEncoding(FormPanel.ENCODING_MULTIPART);
            form.setMethod(FormPanel.METHOD_POST);
            form.setAction("/adt/fileUpload");

            form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler
() {
              public void onSubmitComplete(SubmitCompleteEvent event) {
                // When the form submission is successfully completed, this
event is
                // fired. Assuming the service returned a response of type
text/html,
                // we can get the result text here (see the FormPanel
documentation for
                // further explanation).
                errors.setHTML(event.getResults());
              }});

                file = new FileUpload();
                file.setStylePrimaryName("FileUpload");
                form.add(file);
                this.add(form);



Server Side:

        public void doPost(HttpServletRequest request, HttpServletResponse
response)  throws ServletException, IOException {
        ServletFileUpload upload = new ServletFileUpload();
        System.out.println("Here");
        Enumeration<String>enumer = request.getParameterNames();
        while(enumer.hasMoreElements())
        {
                String name = enumer.nextElement();
                System.out.println(name + " " + request.getParameterValues
(name));
        }
        try{
            FileItemIterator iter = upload.getItemIterator(request);
            System.out.println("Size " + iter.hasNext());
            while (iter.hasNext()) {
                FileItemStream item = iter.next();

                String name = item.getFieldName();
                InputStream stream = item.openStream();


                // Process the input stream
                ByteArrayOutputStream out = new ByteArrayOutputStream
();
                int len;
                byte[] buffer = new byte[8192];
                while ((len = stream.read(buffer, 0, buffer.length)) !
= -1) {
                    out.write(buffer, 0, len);
                }

                int maxFileSize = 10*(1024*2); //10 megs max
                if (out.size() > maxFileSize) {
                    System.out.println("File is > than " +
maxFileSize);
                    return;
                }

                File f = new File(item.getName());
                if(f.exists())
                        f.delete();

                FileOutputStream fos = new FileOutputStream(f);
                byte[] bytes = out.toByteArray();
                fos.write(bytes);

                StandardGridImport sgi = new StandardGridImport();
                sgi.init(f.getPath());
                List<GridBean> beans = sgi.parseGrid();
                        List<CellFormatError> errors = sgi.getErrors();
                        PrintWriter pw = response.getWriter();
                        for(int x = 0; x < errors.size(); x++)
                        pw.write(errors.get(x).toString());
                        pw.flush();
                        pw.close();
                        System.out.println("Done");
            }
        }
        catch(Exception e){
            e.printStackTrace();
        }

    }

--

You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.


Reply via email to