1. #11
    Ext GWT Premium Member
    Join Date
    Jul 2008
    Posts
    101
    Vote Rating
    0
    Martin.Trummer is on a distinguished road

      0  

    Default


    Quote Originally Posted by posta07 View Post
    Unfortunately, I found no way of doing file uploads with RPC :-(
    This is not possible due to browser security restrictions. HTML pages (java-script) are not allowed to read directly from the local file-system.
    The only ways you can access the files:
    • use a form as described in this thread
    • include some object that is allowed to read from the file system: e.g. a java applet

  2. #12
    Ext User
    Join Date
    Aug 2008
    Posts
    2
    Vote Rating
    0
    oswalsarikap is on a distinguished road

      0  

    Default


    Hello All,
    I am new to this GWT world. I m trying to implement File Upload functionality and facing some errors.
    Please help!

    As per above discussions i tried adding the code, i have also imported the commons-fileupload.jar but getting the error as "No source code is available for type org.apache.commons.fileupload.FileUploadException; did you forget to inherit a required module?"

  3. #13
    Ext User
    Join Date
    Aug 2008
    Posts
    2
    Vote Rating
    0
    oswalsarikap is on a distinguished road

      0  

    Default


    Hello All,
    I am new to this extjs and gwt world. I m trying to implement File Upload functionality and facing some errors.
    Please help!

    As per above discussions i tried adding the code, i have also imported the commons-fileupload.jar but still getting some errors related to missing file. I have added to the classpath as well.

    Error

    <H1>HTTP Status 500 - </H1>
    <HR noShade SIZE=1>

    <P><B>type</B> Exception report</P>
    <P><B>message</B> <U></U></P>
    <P><B>description</B> <U>The server encountered an internal error () that prevented it from fulfilling
    this request.</U></P>
    <P><B>exception</B> <PRE>javax.servlet.ServletException: Servlet execution threw an exception
    </PRE>
    <P></P>
    <P><B>root cause</B> <PRE>java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
    org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:191)
    org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:350)
    org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
    org.gwtbook.client.MyFormHandler.getFileItem(MyFormHandler.java:47)
    org.gwtbook.client.MyFormHandler.doPost(MyFormHandler.java:31)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    com.google.gwt.dev.shell.GWTShellServlet.service(GWTShellServlet.java:290)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    </PRE>
    <P></P>
    <P><B>note</B> <U>The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.</U></P>
    <HR noShade SIZE=1>


    <H3>Apache Tomcat/5.0.28</H3>

    Do i need to add the Commons-io.jar as well ? i tried googling it but couldnt find it. Can you please guide what could be wrong while implementing.

    Thanks In Advance!

  4. #14
    Ext User
    Join Date
    May 2008
    Location
    Phoenix, AZ
    Posts
    223
    Vote Rating
    0
    posta07 is on a distinguished road

      0  

    Default


    Do i need to add the Commons-io.jar as well ? i tried googling it but couldnt find it. Can you please guide what could be wrong while implementing.

    Yes, you do need commons-io also. Verify both are correctly on your build path and classpath for when you run the app.

    http://commons.apache.org/io/

  5. #15
    Ext User
    Join Date
    May 2008
    Location
    Phoenix, AZ
    Posts
    223
    Vote Rating
    0
    posta07 is on a distinguished road

      0  

    Default


    Per some requests for the File Download opposite of File Upload, I've posted some hints:

    On the server side I implemented the doGet method of the HttpServlet class. I grab the raw data from the database and set it into the response (with the appropriate response type):

    Code:
                    BufferedOutputStream output = null;
                    try {
                        RawAttachmentItem attachment = attachmentFileDao.retrieveContents(fileid);
                        ByteArrayInputStream input = new ByteArrayInputStream(attachment.getContents());
                        int contentLength = input.available();
                        
                        resp.reset();
                        resp.setContentType("application/octet-stream");
                        resp.setContentLength(contentLength);
                        resp.setHeader("Content-disposition", "attachment; filename=\"" + attachment.getFilename()
                            + "\"");
                        output = new BufferedOutputStream(resp.getOutputStream());
                        for(int data; (data=input.read()) != -1;) {
                            output.write(data);
                        }
                        output.flush();
                    }
                    catch (IOException e) {
                        
                        e.printStackTrace();
                    }
                    finally {
                        close(output);
                    }
    On the client side, you simple create a new iFrame with its 'src' attribute set to the servlet url for downloading the file:

    Code:
            boolean frameExists = (RootPanel.get("downloadiframe") != null);
            if(frameExists) {
                Widget widgetFrame = (Widget)RootPanel.get("downloadiframe");
                widgetFrame.removeFromParent();
            }
            
            NamedFrame frame = new NamedFrame("downloadiframe");
            frame.setUrl(GWT.getModuleBaseURL() 
                + "/attachmentHandler?action=dl&fileid="
                + model.getFileId());
            frame.setVisible(false);
            
            RootPanel.get().add(frame);
    When the file gets sent back to the iFrame, the browser will treat it as a file download and prompt you to do something with it (open, save, cancel, etc).

    If anyone has questions or requires more detail, please do not hesitate to ask!!

  6. #16
    Ext User
    Join Date
    Aug 2008
    Posts
    1
    Vote Rating
    0
    javier.garcia.parra is on a distinguished road

      0  

    Default basic steps to get upload working

    basic steps to get upload working


    After reading your work, and a couple of ... got it to work. This is what I consider more important. It's almost perfectly described in :
    http://home.izforge.com/index.php/20...le-web-toolkit

    Just must now:
    - I added the FileUpload to a FormPanel and this to a GWTExt Panel and look very nice.
    - It is required to set the name of the FileUpload widget. Otherwise you'll get crazy with a silent empty list on the servlet...

    Enjoy coding!!

  7. #17
    Ext User
    Join Date
    Aug 2008
    Posts
    5
    Vote Rating
    0
    qwertz is on a distinguished road

      0  

    Default


    Hi,

    is it possible to combine the GWT FileUpload with other GXT FormWidgets?
    I want to implement a file upload with additional metadata...

  8. #18
    Ext User
    Join Date
    Apr 2008
    Posts
    376
    Vote Rating
    0
    zaccret is on a distinguished road

      0  

    Default


    File upload support is planned for 1.2 : http://www.extjs.com/products/gxt/roadmap.php

  9. #19
    Sencha User
    Join Date
    Aug 2008
    Posts
    226
    Vote Rating
    2
    TheBuzzer is on a distinguished road

      0  

    Default


    it is possible. like i said my project i did it already.

  10. #20
    Ext GWT Premium Member
    Join Date
    Dec 2010
    Location
    New York, NY
    Posts
    116
    Vote Rating
    0
    amit.vankadia is on a distinguished road

      0  

    Default


    i look at your upload example which returns the uploaded file but how do i display that binary data as an Image. if i upload an image