File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes apache.commons.fileupload - Browser blocks ajax requests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "apache.commons.fileupload - Browser blocks ajax requests" Watch "apache.commons.fileupload - Browser blocks ajax requests" New topic
Author

apache.commons.fileupload - Browser blocks ajax requests

Tobias Guennewig
Greenhorn

Joined: Mar 01, 2011
Posts: 4
Hi everyone,

I hope you can help me with my problem.
I want to have a progressbar at my page, which displays the status of a fileupload.

Therefore I got a <h:form>-tag like this :







When the user clicks the commandButton the upload is started. On the server side the send request is wrapped and the request is parsed by a ServletFileUpload object. This looks like this:






The installed ProgressListener just sets a sessionvariable called "FileUpload.Progress.finished" if the upload is ready. Furthermore the percentage of written bytes is stored in the session under the key "FileUpload.Progress.file" (You can't see it here, its done while writing the Fileitems to disk).



There is also registered a onclick listener to the button, which starts the polling. It is sending an ajax.request to render the progressbar.

The javascript looks like this :







Okay,we nearly got it : ) . Last there is the uploadBean.upload method :







This method gets invoked before the page gets rendered. Thats because i registered a preRenderView event listener to the page. This means, that this method gets called after every send ajax request, which goes through the partial lifecycle to render the progressbar. The method eventually adds new Bytes to the progressElements list. The list gets used by the ui:repeat element to build the progressbar. Finally the method checks if the FileUpload.Progress.finished attribute was set by the ProgressListener, which we installed to the ServletFileUpload instance (you remember ? ; ) ).

Ok, i hope you understood the set up. And now to my problem. When i upload a file, there are no ajax requests send, while uploading. The result is that my progressbar doesnt update itself.



Do you know a workaround, or at least can tell me the reason of this ?
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218

I'm sorry to say that I'm too busy to read through all of the stuff that you've gone to the trouble of
posting - however my experience has been that the tomahawk fileupload, and possibly anything in
a multipart form does not support ajax. The whole issue of uploading and downloading files has
been nothing but trouble from start to the present day. I now have a solution that allows file upload
via tomahawk fileupload and download via a servlet and h:graphicImage. I've adopted the "let's
just get the main job done and avoid any of the fancy stuff" approach and I'd suggest that you do
the same unless you have 2-3 months contingency built in to your project plan that you want to use
messing around with this stuff.

Brendan.
Tobias Guennewig
Greenhorn

Joined: Mar 01, 2011
Posts: 4
Brendan Healey wrote:
I'm sorry to say that I'm too busy to read through all of the stuff that you've gone to the trouble of
posting - however my experience has been that the tomahawk fileupload, and possibly anything in
a multipart form does not support ajax. The whole issue of uploading and downloading files has
been nothing but trouble from start to the present day. I now have a solution that allows file upload
via tomahawk fileupload and download via a servlet and h:graphicImage. I've adopted the "let's
just get the main job done and avoid any of the fancy stuff" approach and I'd suggest that you do
the same unless you have 2-3 months contingency built in to your project plan that you want to use
messing around with this stuff.

Brendan.


Hey, thanks four your reply.

I actually don't use the Tomahawk fileupload-tag, I'm using my own crafted staff. I did sum research and got stuck on the richfaces fileupload tag. It seems that this tag offers a progressbar. But I'm wondering how they made it work. I think i will try to integrate the richfaces tag into my project. But i realy would like to know, why my ajax polling doesn't work. The richfaces tag is also working with ajax, but their progressbar gets updated.

I think the problem is the parseRequest method of the ServletFileUpload instance in the constructor of the RequestWrapper. I think the control Thread remains in this method until all files were uploaded. And for some reason, the same client cant send any requests , while the other request isn't fulfilled.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15961
    
  19

Http normally sends data as an atomic unit, which is why basic file upload progress bars don't work. They go from 0% ... long delay ... 100% with nothing in between.

Without actually checking, I think RichFaces is breaking the upload request into chunks so that it can monitor fractional progress.

I have used the RichFaces upload and it works well for me. Personally, I think it would be better to use the standardized off-the-shelf plugin solution (RichFaces) over spending a lot of time designing, debugging, and puzzling out quirks.


Customer surveys are for companies who didn't pay proper attention to begin with.
Tobias Guennewig
Greenhorn

Joined: Mar 01, 2011
Posts: 4
Tim Holloway wrote:Http normally sends data as an atomic unit, which is why basic file upload progress bars don't work. They go from 0% ... long delay ... 100% with nothing in between.

Without actually checking, I think RichFaces is breaking the upload request into chunks so that it can monitor fractional progress.

I have used the RichFaces upload and it works well for me. Personally, I think it would be better to use the standardized off-the-shelf plugin solution (RichFaces) over spending a lot of time designing, debugging, and puzzling out quirks.


Thanks for your reply. I already gone the RichFaces way. Besides I thank you for your explanation how richfaces may progress the upload, it drived me crazy not to know how they solved the problem ; )



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: apache.commons.fileupload - Browser blocks ajax requests
 
Similar Threads
Accepting File Uploads to Server
Session in HTTPServlet
Submit multipart and form data
problem with fileUpload
Problem while uploading xls file through Servlet program.