Java Reference
In-Depth Information
Once the data is prepared in a manner that the web server can
understand (see previous bullet), we attach it to the OutputStream
instance as follows:
var data = conv.encodeParameters (postData);
There's more...
For further details, see:
F Java IO Tutorial—
See also
F Chapter 4—Creating a form with JavaFX controls
F Accessing remote data with HttpRequest
Uploading files to servers with HttpRequest
When creating fully connected rich client applications, part of the expected standard
functionalities, sometimes, is the ability to exchange files with the server. We have already
seen how to download an image from the server (see recipe Downloading images with
HttpRequest ). In this recipe, we will look at how to use HttpRequest to upload an image
to the server.
Getting ready
The concepts presented here deals with HTTP and the HttpRequest object in JavaFX. You
should already have an understanding of the basic mechanics behind the Web and how
HttpRequest interacts with web servers to handle the request/response life cycle. Refer to
the recipes Accessing remote data with HttpRequest , Downloading images with HttpRequest ,
and Posting data to remote servers with HttpRequest , in this chapter, for some background
information on how to use the HttpRequest object to interact with a web server.
For this recipe, we will assume that we have a web server running an application which
can process the submission of a multi-part form for image file upload running at the
address— . JavaFX's
HttpRequest object does not support file upload directly (as of version 1.2). However, in
this recipe, we will use common (and publicly available) knowledge about multi-part web
forms to create the low-level data stream required by HTTP for multi-part form submission
for file upload.
Search WWH ::

Custom Search