JavaFX - Upload and Download Large Files
By Rakesh Menon on Jun 17, 2009
We can upload or download large files using new HttpRequest attributes available in JavaFX 1.2.
HttpRequest has input and onInput attributes that provides InputStream which can be used to download data. This stream supports mark, reset, available, skip etc. But to support this HttpRequest buffers the data. Due to this buffering it was not possible to use this approach to download large files.
JavaFX 1.2 introduce two new attributes - source (InputStream) and sink (OutputStream). If we set
sink attribute, we can directly download the content of stream without buffering. Also with
source we can upload the content. Eg: By setting it to FileInputStream. When source or sink attribute is used, corresponding input, onInput, output, onOutput will not be functional.
<script src="http://dl.javafx.com/1.2/dtfx.js"></script><script src="/rakeshmenonp/resource/UploadDownload/UploadDownload.js"></script>
For Applet mode, click on above image
In above sample,
sink is assigned to a
FileOutputStream. So all the content will be directly written to file without buffering. Note: For making the application compatible with mobile or other platforms we will have to use only subset of
java.io package. Example: MID Profile Core API.
Update: Please refer to post on Upload File as well.