Hybrid View

  1. #1
    Ext User
    Join Date
    Mar 2010
    Posts
    2
    Vote Rating
    0
    Changhee is on a distinguished road

      0  

    Default 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
    PHP Code:
    public class AGISFileDispatcher extends HttpServlet {
     
        public 
    void doPost(HttpServletRequest reqHttpServletResponse resp)
                
    throws ServletExceptionIOException {
         try{
             
    resp.setContentType("text/html");
             
    parsing(req);
             
    MyDispatcher a = new MyDispatcher();
             
    a.saveFile(reqresp);
     
                }catch(
    AgisException ex)
             {
                 
    ex.printStackTrace();
             }
        } 
    Thanks!

  2. #2
    Sencha User
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    82
    Vote Rating
    0
    g1_ is on a distinguished road

      0  

    Default


    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?

  3. #3
    Ext User
    Join Date
    Mar 2010
    Posts
    2
    Vote Rating
    0
    Changhee is on a distinguished road

      0  

    Default


    right. Upload works well, but client can not know whether upload is complete or not..

  4. #4
    Sencha User
    Join Date
    Mar 2008
    Posts
    5
    Vote Rating
    0
    dimon is on a distinguished road

      0  

    Default


    // 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 :

    Code:
    form.addListener(Events.Submit, new Listener<FormEvent>() {
    	@Override
    	public void handleEvent(FormEvent be) {
    		be.getResultHtml();
    	}
    });
    Absence of server response decoding is an obvious GXT documentation flaw,
    but there's a whole lot of work these men already managed to do for us.))

  5. #5
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Yes you get the response in that event, the Events.Submit event.

  6. #6
    Sencha Premium Member
    Join Date
    May 2010
    Posts
    28
    Vote Rating
    0
    donp is on a distinguished road

      0  

    Default


    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:

    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>
    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.

    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.