JavaFX - Upload File
By Rakesh Menon on Feb 03, 2010
One of the previous post had a sample to download large files using JavaFX. It relies on HttpRequest attribute sink to specify the output file location. Similarly we can use source attribute for uploading a file.
I have written a simple UploadServlet to receive the file content and save at <user.home>/JavaFXDownloads/ location.
Relevant part of JavaFX client code is given below..
Name of file is passed as argument to upload servlet. This URL is encoded using URLConverter. The file to be uploaded is assigned to source attribute. Http content-type is set to "multipart/form-data". You can host the UploadServlet - server - code in any webserver such as Tomcat, Glassfish etc. Value of uploadServletURL in JavaFX client must be updated to point to this servlet URL.
I found another sample code Multipart HTTP file upload with JavaFX which demonstrates alternate approach.
Try it out and let me know feedback..