fileupload in gwt

420 views
Skip to first unread message

kim young ill

unread,
Feb 14, 2012, 3:59:31 AM2/14/12
to google-we...@googlegroups.com
hi there
what's the best approach to handle a simple fileupload in gwt ?
normally it would be a normal POST with File-Field, problem is that a post to a servlet will make the page "refresh", that means user will be redirect from current page. is there a lightweight-approach which doesnt require this ? possibly an iframe which contains the form ?

thanx

Thomas Broyer

unread,
Feb 14, 2012, 5:29:52 AM2/14/12
to google-we...@googlegroups.com
FormPanel defaults to submitting to an hidden iframe; couple that with a FileUpload widget and you're done.
Have a look at the GWTUploader project too.

kim young ill

unread,
Feb 14, 2012, 6:47:10 AM2/14/12
to google-we...@googlegroups.com
ahh,
thanx, i'll have a look.

On Tue, Feb 14, 2012 at 11:29 AM, Thomas Broyer <t.br...@gmail.com> wrote:
FormPanel defaults to submitting to an hidden iframe; couple that with a FileUpload widget and you're done.
Have a look at the GWTUploader project too.

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

thalys...@cardif.com.br

unread,
Feb 14, 2012, 6:18:26 AM2/14/12
to google-we...@googlegroups.com

Hello, Everybody

I found a good sample here http://fkgwt20.googlecode.com/svn/mvpproject/, this Project that have several kind of examples included file upload that you can use of GWT.



Internet  
t.br...@gmail.com

Enviado Por: google-we...@googlegroups.com

14/02/2012 08:29


Para
google-we...@googlegroups.com
cc
Assunto
Re: fileupload in gwt





FormPanel defaults to submitting to an hidden iframe; couple that with a FileUpload widget and you're done.
Have a look at the GWTUploader project too.

--

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit

https://groups.google.com/d/msg/google-web-toolkit/-/Qal0aW3JnE8J.

Amith K Bharathan

unread,
Feb 14, 2012, 11:56:46 PM2/14/12
to google-we...@googlegroups.com

Create a servlet in server and config it in web.xml

kim young ill

unread,
Mar 8, 2012, 8:54:41 AM3/8/12
to google-we...@googlegroups.com
anyone know how to handle a cancel-upload case ?
i guess if the client just cut the line. server will get IOException & can handle that. what about clientside with FileUpload widget (or i guess  Formpanel should do sth here )?

thanx


On Wed, Feb 15, 2012 at 5:56 AM, Amith K Bharathan <amithkb...@gmail.com> wrote:

Create a servlet in server and config it in web.xml

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

Brandon Donnelson

unread,
Mar 10, 2012, 5:31:26 PM3/10/12
to google-we...@googlegroups.com
I've found can trick the formpanel self target by setting the target to null. If you wanted to post and redirect to servlet this is how I'd do it. I've also sharded data and uploaded it over rpc using the file reader, but this api is still limited. 

    FormPanel form = new FormPanel((String) null); // (String) null gets rid of self target
    form
.setAction(action);
    form
.setMethod(FormPanel.METHOD_POST);

Brandon 

kim young ill

unread,
Mar 10, 2012, 6:22:52 PM3/10/12
to google-we...@googlegroups.com
thanx, i'll try it out. that's weird thou since its not documented anywhere.



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

JoyaleXandre

unread,
Mar 12, 2012, 1:36:24 PM3/12/12
to google-we...@googlegroups.com
You can use something this code, I think it's self explaining.

// Create a FormPanel and point it at a service.
    final FormPanel form = new FormPanel();
    form.setAction(GWT.getHostPageBaseURL() + YOUR_SERVLET_PATH_HERE);

    // To upload a file with the form we need to set to multipart MIME encoding and POST method.
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    // Create a panel to hold all of the form widgets.
    panel = new VerticalPanel();
    form.setWidget(panel);

    // Create a FileUpload widget.
    final FileUpload upload = new FileUpload();
    upload.setName("file");
    panel.add(upload);

    [SOME OTHER CODE HERE IF YOU WANT]

    // Add a submit button.
    final Button btnSubmit = new Button("Upload package");
    btnSubmit.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
        if (upload.getFilename().length() == 0)
            Window.alert("The file path must not be empty");
        else {
            form.submit();
          }
        }
    });
    panel.add(btnSubmit);
Reply all
Reply to author
Forward
0 new messages