GWT File Upload issue

68 views
Skip to first unread message

ashwin...@gmail.com

unread,
Apr 9, 2009, 1:58:32 AM4/9/09
to Google Web Toolkit Contributors
Hi All,

I am getting multipart false on server side even i am setting it
(ENCODING_MULTIPART) on client side.



My Code
------------------------------------------------------------------------------------


1. GWT widget: FormHandle

RootPanel rootPanel = RootPanel.get();

final FormPanel form = new FormPanel();
rootPanel.add(form);
form.setAction(GWT.getModuleBaseURL()+"MyFormHandler");
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
.........
.........
.........

panel.add(new Button("Submit", new ClickListener() {
public void onClick(Widget sender) {
form.submit();
}
}));

.........
.........
.........

form.addFormHandler(new FormHandler() {
public void onSubmit(FormSubmitEvent event) {
service.fileUpload(new AsyncCallback(){
public void onFailure(Throwable caught) {
Window.alert("FileUpload Failure!!");
}

public void onSuccess(Object result) {
Window.alert("FileUpload Success!!");
}});
event.setCancelled(true);
}

public void onSubmitComplete(FormSubmitCompleteEvent event) {
Window.alert(event.getResults());
}
});

RootPanel.get().add(form)

2. Servlet:: MyFormHandlerImpl

public class MyFormHandlerImpl extends RemoteServiceServlet implements
MyFormHandler {

/**
*
*/
private static final long serialVersionUID = 1L;

@Override
public void fileUpload() {
System.out.println("0");
HttpServletRequest request = super.getThreadLocalRequest();
HttpServletResponse response = super.getThreadLocalResponse();

boolean isMultiPart =
FileUpload.isMultipartContent(request);//isMultipartContent(request)

String parentPath ="d:\\";

if (isMultiPart) {
System.out.println("3");
DiskFileUpload upload = new DiskFileUpload();
try {
List items = upload.parseRequest(request);
Iterator it = items.iterator();
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
if(!item.isFormField()){
File fullFile = new File(item.getName());
File savedFile = new File(parentPath,fullFile.getName());
item.write(savedFile);
}
}
} catch (FileUploadException fUE) {
System.out.println("file not found");
} catch (Exception e){
System.out.println("unknown exception");
}
}

}
}
------------------------------------------------------------------------------------------------------------

Can anybody tell me what i am missing here?
what could be done to resolve this error?

Thanks in advance for your help.

Arun.

Dug

unread,
Apr 14, 2009, 9:00:28 AM4/14/09
to Google Web Toolkit Contributors
Hi arun

U can use GwtSwfExt lib for uploading files(gmail style file upload).
This lib is wrapper on SWFUpload .
http://code.google.com/p/gwtswfext/

Thanks
Dug

On Apr 9, 12:58 am, "arun.r...@gmail.com" <ashwinkva...@gmail.com>
wrote:
> Hi All,
>
> I am getting multipart false on server side even i am setting it
> (ENCODING_MULTIPART) on client side.
>
> My Code
> ---------------------------------------------------------------------------­---------
>
> 1.GWTwidget: FormHandle
> DiskFileUploadupload= new DiskFileUpload();
> try {
> List items =upload.parseRequest(request);
> Iterator it = items.iterator();
> while (it.hasNext()) {
> FileItem item = (FileItem) it.next();
> if(!item.isFormField()){
> File fullFile = new File(item.getName());
> File savedFile = new File(parentPath,fullFile.getName());
> item.write(savedFile);}
> }
> } catch (FileUploadException fUE) {
>
> System.out.println("file not found");} catch (Exception e){
>
> System.out.println("unknown exception");
>
> }
> }
> }
> }
>
> ---------------------------------------------------------------------------­---------------------------------

Jason Essington

unread,
Apr 14, 2009, 11:03:52 AM4/14/09
to Google-Web-Tool...@googlegroups.com
I fail to see how this resolves arun's "bug" with GWT form panel

-jason

Thomas Broyer

unread,
Apr 15, 2009, 5:28:14 AM4/15/09
to Google Web Toolkit Contributors


On 14 avr, 17:03, Jason Essington <jason.essing...@gmail.com> wrote:
> I fail to see how this resolves arun's "bug" with GWT form panel

Arun's issue is with his code, not the FormPanel:

Jason Essington

unread,
Apr 15, 2009, 1:10:31 PM4/15/09
to Google-Web-Tool...@googlegroups.com
agreed, that was the reason for quoting the word bug ...

This discussion really belongs on the user list.

Arun: looks like you are sending an RPC in the onSubmit() of the
form ... RPCs really have nothing to do with the form submission, and
expecting the request of the RPC to adopt the multipart encoding of
the form is unreasonable.

There are samples floating around for using a form submission with
multipart encoding (google GWT file upload), have a look at how that
is done.

-jason
Reply all
Reply to author
Forward
0 new messages