Java Reference
In-Depth Information
How to do it...
The abbreviated code given next shows you the major components needed to achieve
binary data upload to a remote web server. Refer to ch06/source-code/src/http/
HttpRequestFileUpload.fx for a complete code listing.
1. The first portion of the code defines class FormPart used to encapsulate the binary
data and the required HTTP multi-part boundary markers that are used to decorate
the data so the server can parse it.
def MARKER = "--";
def CRLF = "\r\n";
def BOUNDARY = "7d226f700d0";
def CONTENT_TYPE = "multipart/form-data; boundary={BOUNDARY}";
class FormPart {
public-init var name:String;
public var value:String;
public var file:File;
var conv = URLConverter{}
public function writeFileTo ( out :OutputStream):Void {
if(file != null){
var header = new java.lang.StringBuilder();
.append("Content-Disposition: form-data;
.append("Content-Type: application/octet-stream")
// write header to output stream
out. write (header.toString().getBytes());
// copy file content to out stream
var byteRead:Integer;
var input = new FileInputStream (file);
while ((byteRead = != -1){
out .write( byteRead );
Search WWH ::

Custom Search