GWT RPC file upload problem

GWT Designer allows you to quickly create the modules, composites, panels, remote services and other elements that comprise Google Web Tookit applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

GWT RPC file upload problem

Postby arun.raai » Wed Apr 08, 2009 10:32 pm

Hi All,

I am getting multipart null even it is set (ENCODING_MULTIPART) on client side.

I am working with gwt 1.5.3
-------------
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.
arun.raai
 
Posts: 1
Joined: Wed Apr 08, 2009 10:28 pm

Re: GWT RPC file upload problem

Postby Eric Clayberg » Thu Apr 09, 2009 3:26 am

I'm sorry, but general GWT questions should be directed to Google's GWT forum.

Thus forum is for GWT Designer related questions only.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to GWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests