Uploading files using HTTP |
To upload a file create a new HttpFileUpload instance providing the URL designated to handle file upload requests in the constructor. To set the data to be uploaded use the HttpFileUpload#setFile method. The first argument in the HttpFileUpload#setFile method is the field name and should match the parameter name expected by your server-side code to contain file upload data. The HttpFileUpload is a subclass of HttpRequest so you may use it in the same way that you use the HttpRequest class to request web pages
Example
// create new Http instance Http http = new Http();
// create new HttpFileUpload instance HttpFileUpload request = new HttpFileUpload("http://www.myserver.com/cgi-bin/upload.cgi");
// add parameter request.addParameter("name", "John Doe");
// set file data to upload and store as named parameter "picture" request.setFile("picture", "joe.gif", new File("/home/joe/joe.gif");
// upload file and get response HttpResponse response = http.getResponse(request);
|