JavaFX - Upload File


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..

def uploadServletURL = 
    
"http://localhost:8080/server/UploadServlet";

def urlConverter = URLConverter{ };
def encodedServletURL = urlConverter.encodeURL(
    "{uploadServletURL}?file={inputFile.getName()}")

def httpRequest: HttpRequest = HttpRequest {

    location: encodedServletURL    
    source: new java.io.FileInputStream(inputFile)
    method: HttpRequest.POST

    headers: [
        HttpHeader {
            name: HttpHeader.CONTENT_TYPE
            value: "multipart/form-data"
        }
    ]
}

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..


<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://javafxdemos.googlecode.com/hg/resource/UploadFile/zoneit.js"></script>

Comments:

1) is it posible to render a PDF in javaFx window
if yes how can we do that.

please help to get proper inforation

Thanks
Tijomon Mathew

Posted by need help on rendering pdf using javafx and upload the file back to server on April 23, 2010 at 08:12 AM IST #

@Tijomon Mathew JavaFX directly doesn't have any API to render PDF. But you may try java libraries and use it in JavaFX, such as https://pdf-renderer.dev.java.net/

Posted by Rakesh Menon on April 23, 2010 at 09:11 AM IST #

Post a Comment:
Comments are closed for this entry.
About


The views expressed on this blog are my own and do not necessarily reflect that of my organization

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today