Search code examples
javagwtgwt-rpcgwt2

How to transfer a file From Client to Server in GWT using fileUpload


I have code to browse a file .

i have to send the file to server side. I dont know how to pass file to Server Using RPC.

  formPanel.addFormHandler(new FormHandler() {

        public void onSubmitComplete(final FormSubmitCompleteEvent event) {
            // TODO Auto-generated method stub
            Window.alert(event.getResults());
        }

        public void onSubmit(final FormSubmitEvent event) {
            // TODO Auto-generated method stub
            event.setCancelled(true);
        }
    });
 formPanel.setMethod(FormPanel.METHOD_POST);
 formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
 formPanel.setWidget(holder);
 holder.add(upload);
 btnAdd.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            // *
        }
    });

 // holder is vertical Panel

on this btnAdd clickhandler i have to transfer a file to server with all its contents. On serverside i have to read the content, file name. Plz help me with the Interface ,interfaceAsync ,service , and server side.


Solution

  • Please see the link below.

    http://commons.apache.org/fileupload/using.html

    Also pls keep in mind that when you deploy the app you'll need commons-io-2.1.jar too.