Java Reference
In-Depth Information
2. The second part of the code utilizes HttpRequest in conjunction with the
FormPart class to send the multi-part form to the the server.
def url = "http://localhost:8080/webapp/upload/save";
def file = new File("image.png");
def fileLen = file.length();
// HttpRequest declaration which uses class FormData
var http:HttpRequest = HttpRequest {
location: url
method: HttpRequest.POST
headers : [
{name:HttpHeader.CONTENT_TYPE value:CONTENT_TYPE},
onOutput :function(out: OutputStream){
try {
// write parts
def filePart = FormPart {name:"file" file:file}
filePart.writeFileTo (out);
// close multipart with a footer
var footer = new java.lang.StringBuilder();
out.write (footer.toString().getBytes());
When this code is executed, it will invoke HttpRequest.start() , which will cause the
content of the file image.png to be uploaded to the server.
Search WWH ::

Custom Search