Hybrid View
-
29 Apr 2010 4:16 PM #1
File Upload
File Upload
Hi.
Because I could not find proper server-side sample for ExtGWT File Upload,
I have made upload with FormPanel for client side and "extends HttpServlet" for Server-side , not "extends RemoteServiceServlet ".
Problem is that I could not get any response such as Callback or HttpResponse of upload results
1. How can I get or handle the response after upload complete?
2. Is there no sample file uplod for server-side with "RemoteServiceServlet"? if it is, please let me know~
Client
PHP Code:final FormPanel panel = new FormPanel();
panel.setHeading("File Upload Example");
panel.setFrame(true);
panel.setAction("/upload");
panel.setEncoding(Encoding.MULTIPART);
panel.setMethod(Method.POST);
..
..
btn.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
if (!panel.isValid()) {
return;
}
// normally would submit the form but for example no server set up to
// handle the post
panel.submit();
MessageBox.info("Action", "You file was uploaded", null);
}
});
Server
Thanks!PHP Code:public class AGISFileDispatcher extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try{
resp.setContentType("text/html");
parsing(req);
MyDispatcher a = new MyDispatcher();
a.saveFile(req, resp);
}catch(AgisException ex)
{
ex.printStackTrace();
}
}
-
30 Apr 2010 12:35 AM #2
Just to clarify:
Your code works, but you would like to modify it in such a way that the client is notified when the upload is complete?
-
30 Apr 2010 12:46 AM #3
right. Upload works well, but client can not know whether upload is complete or not..
-
15 Oct 2010 7:23 AM #4
// according to FormPanel.java (line 563, in v2.1.1):
I think that iFrame content will be updated on server response.
And you can use decode the response using the following :
Absence of server response decoding is an obvious GXT documentation flaw,Code:form.addListener(Events.Submit, new Listener<FormEvent>() { @Override public void handleEvent(FormEvent be) { be.getResultHtml(); } });
but there's a whole lot of work these men already managed to do for us.))
-
15 Oct 2010 7:56 AM #5
Yes you get the response in that event, the Events.Submit event.
-
24 Sep 2012 7:08 AM #6
Sven/GXT team -
This is an ongoing issue.
I'm not sure that Sven's comment "Yes, you get the response in that event" is accurate.
When I look at the event, in resultHtml I see something like this:
The common case here, is that we submit a form to create a server object based on the Form's model. In my case, this is complicated by the fact that I'm uploading a file (an image), which is part of what the server will use to create its object. However, a common scenario is to submit data from a form, and validate on the server whether an existing object with the same name/ID exists, and then send a response back with a status code and message like "The object could not be created, because it already exists". This "error" response would be caught in the submit request's callback, so that an informative message can be shown to the user.Code:<h1>HTTP Status 501 - Q2Fubm90IGNyZWF0ZSBpbWFnZSB3aXRoIG5hbWUgdGVzdDMyMF8xMDAucG5nLiBUaGlzIGltYWdlIGFscmVhZHkgZXhpc3RzLg==</h1><hr size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Q2Fubm90IGNyZWF0ZSBpbWFnZSB3aXRoIG5hbWUgdGVzdDMyMF8xMDAucG5nLiBUaGlzIGltYWdlIGFscmVhZHkgZXhpc3RzLg==</u></p><p><b>description</b> <u>The server does not support the functionality needed to fulfill this request (Q2Fubm90IGNyZWF0ZSBpbWFnZSB3aXRoIG5hbWUgdGVzdDMyMF8xMDAucG5nLiBUaGlzIGltYWdlIGFscmVhZHkgZXhpc3RzLg==).</u></p><hr size="1" noshade="noshade"><h3>Apache Tomcat/5.5.23</h3>
How can this be accomplished with a FormPanel submit(), and in particular with a POST request - which is the only way I can see to upload a file/image.
Thanks,
Don P.


Reply With Quote