简体   繁体   中英

How to do file uploads via a Java applet?

Specifically how can I:

  • Show a button which will let the user browse through his computer and select a file
  • Show a progress bar as the files are uploaded
  • And store the files to a location on the server of the website on which the applet is being run

Any ideas? And yes, I must do this in an applet, and I will make it a trusted/signed applet, have looked into all that.

I've had to do just this, with very large (4Gb+) files. The piece of code at the bottom of this Google Answers post helped me out a LOT: http://answers.google.com/answers/threadview?id=193780

It showed a way of uploading files chunked into smaller bits, so you can easily use a JProgressBar.

There is no need to sign the applet since 6u10. Instead you can use the FileOpenService to read the file through a standard Swing file chooser (technically implementation dependent). Then it is just a matter of sending the file back as a browser would with a multipart MIME HTTP POST .

I would load/stream in the file, convert it to Base64 (or not) and send a POST request (using URLConnection) containing it to a servlet at the other end.

From a client side viewpoint its easier than doing a multi-part/form-data file upload and have the Commons FileUpload wait for it on the other end 1 , in my opinion.

1 unless there are libraries available to do just that easily on the client side.

I'm bored. I think I'll just copy the links from the last time I answered this question.

Signed Applet

JFileChooser

JProgressBar

JButton

Apache HttpClient 's PostMethod with a MultipartRequestEntity that wraps the JFileChooser's file in a FilePart ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM