• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Track download completion

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I have a servlet which is used for file download. I want to make sure the user completed the download and depending on that I will update the download status as "DOWNLOADED". If the download aborts in the middle or he/she clicks "Cancel" button on the download popup, the download status will be "NOT_DOWNLOADED". How can I do this?
This is a my current project related issue and I am at a doomed condition. Guys I really need your help!
[ May 24, 2007: Message edited by: Tridib Samanta ]
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't do this through the servlet model because the container abstracts away all the HTTP and TCP so you don't have to worry about the protocols; of course, on the flip side, it does mean you don't have total control.

On the other hand, you wouldn't be able to dynamically do anything with presenting pages using only server-side coding - you'd need to think about using client-side scripting like JavaScript to monitor the download progress, though I'm not sure how that would work since JavaScript can't access the local filesystem (to measure file size/write from stream to disk).

Ultimately, you can track download progress if you know the amount transferred (e.g. from a file size) and the total to transfer (from the HTTP response headers), but you will neither find this information through servlets, nor through most HTTP implementations (since the data written goes into a TCP buffer, and the amount delivered from the buffer isn't guaranteed because the connection can be closed at any time).

Why do you need to do this, and is there no alternative? Is there a website that already achieves so you could use their client-side scripting as a starting point?
 
Tridib Samanta
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Charles! I got your point.
The requirement is like this: These files contain very confidential data. We bring the file from a different environment to our local system. As soon as the user download it, we have to remove it from our local system. But the file should be available for download to the user if the user fails to download the file at first attempt or so.
Could you please suggest any other alternative solution? Thanks in adavance.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Charles Lyons implied, the only way to ensure that the client has finished downloading a file is to have something running on the client to report that completion.

And as he suggested, Javascript is unlikely to work because of the security features that prevent it from accessing files. So what other client-side technologies could you use?

Since you're posting here, you are probably familiar with Java. Java running in a browser? That must be an applet. You would have to sign it to allow it to access files on the client system.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are your users trusted? If so, you could do something as simple as have them let you knw when the download completes.

The USPS uses this technique for their Clik-n-ship facility. After the postage has been downloaded and printed, the web app asks "did it print correctly?". You could do the same sort of thing assuming that you are trusting your users to tell the truth.

If not, then something along the lines of what Paul suggests may be your only option.
 
Charles Lyons
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try an applet, though you'll need to sign it with an appropriate certificate. Then the user will be presented with a dialog asking them if they trust the applet: if not, they won't be able to download the file. If so, the download can progress (you'll probably want to put a progress bar in your applet). Note that this isn't perfect - there are problems on some platforms such as Vista:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6548078

The disadvantage with the applet is: (1) you've got to have all clients supporting your applet + JRE version (this is a real bind); (2) the server still can't determine when the transfer's complete except if your applet signals it somehow (i.e. issues another 'special' HTTP request) after transfer.

Second thought: do you really need to cache it locally at all? Couldn't you configure a proxy so when the client makes an HTTP request to your server, it sends a request to the remote server for the file, and all data returned is buffered to the client? That way you never actually store the file yourself at all. You can implement different security mechanisms at each stage with the proxy if necessary. You can probably find suitable software available (e.g. Apache's modules), or build your own with the Java 6 HTTP server (see below).

Finally, if you really must cache, you could build a second Java application on the server which implements HTTP directly over TCP, and track the underlying connection that way - once the TCP connection (socket) closes or all the data was written, delete the file. This also means your program can monitor the file's last modified date (when it was downloaded to your server), and if it's too far in the past, delete it anyway (assuming the client isn't going to download it - and if they are, they can just go back through the Web page again).

For this last solution, take a look at the new Java 6 HTTP server in packages "com.sun.net.httpserver":

http://java.sun.com/javase/6/docs/jre/api/net/httpserver/spec/index.html

You'll also need to be familiar with java.net to get it working, but by all accounts it shouldn't be too difficult. Your only problem then is clients with firewalls which block non-standard ports, since you'll have to run your program as a daemon on another port.

Does that help?
 
Tridib Samanta
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everybody for your great replies.
I think using applet is more appropriate for my project requirement.
As, Bear suggested, I also thought to let the user confirm the download. But after download, they may skip this step and the documents may be still available.
Thanks Charles for your suggested solutions. But it seems very tough and I don't have sufficient knowledge to implement those. I must give a try later.

Thanks again everybody.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic