-
7 Aug 2008 11:52 PM #11
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
-
18 Aug 2008 2:42 AM #12
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?"
-
18 Aug 2008 3:28 AM #13
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 fulfillingthis 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!
-
18 Aug 2008 4:51 AM #14
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/
-
27 Aug 2008 5:12 AM #15
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):
On the client side, you simple create a new iFrame with its 'src' attribute set to the servlet url for downloading the file: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); }
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).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);
If anyone has questions or requires more detail, please do not hesitate to ask!!
-
28 Aug 2008 2:05 AM #16
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!!
-
4 Sep 2008 4:59 AM #17
Hi,
is it possible to combine the GWT FileUpload with other GXT FormWidgets?
I want to implement a file upload with additional metadata...
-
23 Oct 2008 4:56 AM #18
-
23 Oct 2008 7:07 AM #19
it is possible. like i said my project i did it already.
-
1 Dec 2010 3:44 PM #20
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



Reply With Quote