Secure iNet Factory

com.jscape.inet.http
Class HttpFileUpload

java.lang.Object
  extended by com.jscape.inet.mime.MimeMessage
      extended by com.jscape.inet.http.HttpRequest
          extended by com.jscape.inet.http.HttpFileUpload
All Implemented Interfaces:
MimeConstants, java.io.Serializable

public class HttpFileUpload
extends HttpRequest

Implements methods for emulating a web browser and performing HTTP file upload based on specifications defined in RFC 1867.

Example Usage:

 Http http = new Http();
 HttpFileUpload request = new HttpFileUpload("http://www.myserver.com/cgi-bin/upload.cgi");
 request.addParameter("name", "John Doe");
 request.setFile("picture", "joe.gif", new File("/home/joe/joe.gif");
 HttpResponse response = http.getResponse(request);
 

See Also:
Serialized Form

Field Summary
static java.lang.String PLACEHOLDER
          Place holder string for file data.
 
Fields inherited from interface com.jscape.inet.mime.MimeConstants
COLON, CRLF, EQUALS, QUESTION_MARK, SEMI_COLON, SPACE, TAB
 
Constructor Summary
HttpFileUpload(java.lang.String url)
          Constructs a new HttpFileUpload instance.
 
Method Summary
 void addParameter(HttpParameter parameter)
          Adds a query parameter to HttpFileUpload.
 void addParameter(java.lang.String name, java.lang.String value)
          Adds a query parameter to HttpFileUpload.
 boolean IsStreamingEnabled()
          Streaming.
 void setFile(java.lang.String fieldName, java.lang.String filename, byte[] data)
          Sets the file to upload for this HttpFileUpload.
 void setFile(java.lang.String fieldName, java.lang.String fileName, java.io.File file)
          Sets the file to upload for this HttpFileUpload.
 void streamFileToServer(java.lang.String fieldName, java.lang.String fileName, java.io.File file)
          Stream file to HTTP server instead of reading entire File object in RAM.
 
Methods inherited from class com.jscape.inet.http.HttpRequest
addCookie, addHeader, addHeader, addReplaceHeader, addReplaceHeader, addReplaceParameter, addReplaceParameter, clearCookies, clearParameters, getHttpVersion, getMessage, getMethod, getParameters, getProxyHost, getProxyPort, getProxyUsername, getURL, getUserAgent, isUTF8, setBasicAuthentication, setHttpVersion, setMethod, setProxyHost, setProxyLogin, setProxyPort, setURL, setUserAgent, setUTF8
 
Methods inherited from class com.jscape.inet.mime.MimeMessage
addPart, getBody, getBodyAsFile, getBodyData, getBoundary, getContentTransferEncoding, getContentType, getHeader, getHeaders, getHeaders, getHeaderValue, getPart, getParts, getRawBodyData, removeHeader, removePart, removeParts, setBody, setBody, setBody, setBody, setBodyAsFile, setContentType
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLACEHOLDER

public static final java.lang.String PLACEHOLDER
Place holder string for file data.

See Also:
Constant Field Values
Constructor Detail

HttpFileUpload

public HttpFileUpload(java.lang.String url)
               throws HttpException
Constructs a new HttpFileUpload instance.

Parameters:
url - the URL to post the file upload to
Throws:
HttpException - if a MIME related parsing error occurs
Method Detail

addParameter

public void addParameter(java.lang.String name,
                         java.lang.String value)
Adds a query parameter to HttpFileUpload. HTTP query parameters are typically used in submitting form data for processing by a CGI or servlet resident on the HTTP server. Names of query parameters need not be unique.

Overrides:
addParameter in class HttpRequest
Parameters:
name - the name of the parameter to add.
value - the value of the parameter to add.

addParameter

public void addParameter(HttpParameter parameter)
Adds a query parameter to HttpFileUpload. HTTP query parameters are typically used in submitting form data for processing by a CGI or servlet resident on the HTTP server. Names of query parameters need not be unique.

Overrides:
addParameter in class HttpRequest
Parameters:
parameter - the HttpParameter to add
See Also:
HttpParameter

IsStreamingEnabled

public boolean IsStreamingEnabled()
Streaming.

Returns:
boolean value for enable streaming.

streamFileToServer

public void streamFileToServer(java.lang.String fieldName,
                               java.lang.String fileName,
                               java.io.File file)
                        throws HttpException
Stream file to HTTP server instead of reading entire File object in RAM.

Parameters:
fieldName -
fileName -
file -
Throws:
HttpException

setFile

public void setFile(java.lang.String fieldName,
                    java.lang.String fileName,
                    java.io.File file)
             throws HttpException
Sets the file to upload for this HttpFileUpload.

Parameters:
fieldName - the name of the field, as specified in HTML INPUT TYPE=FILE tag
fileName - the value to set the MIME filename attribute to
file - the File object of the file to be added
Throws:
HttpException - if file is not found

setFile

public void setFile(java.lang.String fieldName,
                    java.lang.String filename,
                    byte[] data)
             throws HttpException
Sets the file to upload for this HttpFileUpload.

Parameters:
fieldName - the name of the field, as specified in HTML INPUT TYPE=FILE tag
filename - the value to set the MIME filename attribute to
data - the data representing the file to upload
Throws:
HttpException - if file is not found

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved