|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||
#include "ot/web/MultipartFormEmulator.h"

The use of a random separator makes the multipart/form-data encoding suitable for the transmission of binary data such as data files. Indeed, many Web sites provide a file upload facility via HTML forms using the multipart/form-data encoding.
Please see the FormEmulator class for a code example.
The OpenTop HTTP framework provides the capability to stream entities directly to the underlying socket rather than having to buffer the whole entity in memory prior to transmission. This class enables application developers to take full advantage of this feature, by providing an entity InputStream which can be copied to the HTTP OutputStream while only using a small memory buffer on the client.
When instances of this class return an InputStream entity containing filename fields, what is actually returned is a SequenceInputStream combining byte streams that contain the field header and boundary sequences with InputStreams for the files' data. When the returned SequenceInputStream is read, the result is the headers and file data combined into a contiguous stream of bytes.
In most cases, the length (in bytes) of the entity produced by instances of this class can be calculated and used to construct an Entity-Length MIME header. However, it is possible to construct a form with a filename field comprising an InputStream of unknown length. In this case, the form's entity length cannot be determined and the entity will need to be transported using either the HTTP/1.1 chunked encoding or a non-persistent HTTP connection (where the end of the entity is signalled by closing the stream). See the HttpRequest class for further information about sending entities.
| Constructor/Destructor Summary | |
MultipartFormEmulator()Default constructor. | |
MultipartFormEmulator(const String& encoding)Constructs a new MultipartFormEmulator with the name of the encoding to be used for field values. | |
| Method Summary | |
virtual void |
addField(const String& name, const String& value)Inserts a name/value pair field to the end of the sequence of fields contained by this form. |
virtual void |
addFilenameField(const String& fieldName, const File& file, const String& filename, const String& encoding, const String& mimeType)Inserts a filename field to the end of the sequence of fields contained by this form. |
virtual void |
addFilenameField(const String& fieldName, InputStream* pStream, const String& filename, const String& encoding, Int64Type fileLength, const String& mimeType)Inserts a filename field to the end of the sequence of fields contained by this form. |
virtual void |
clear()Clears all the fields, returning the form to its newly constructed state. |
static ByteString |
GenerateRandomSeparator(const ByteString& prefix, size_t length)Static function to generates a new random byte string intended to mark the boundary between individual parts of a multipart form. |
virtual String |
getContentTypeHeader() constReturns a Content-Type header value describing the MIME type of the form entity. |
virtual RefPtr< InputStream > |
getEntity() constReturns an InputStream which provides a contiguous stream of bytes constituting the form entity. |
virtual Int64Type |
getEntityLength() constReturns the length of the form entity. |
const ByteString& |
getSeparator() constReturns the ByteString used to separate parts of the multipart form data. |
void |
regenerateSeparator()Sets the ByteString used to separate individual parts of the multipart form data to a new randomly generated string. |
void |
setSeparator(const ByteString& sep)Sets the ByteString used to separate individual parts of the multipart form data. |
void |
writeEntity(OutputStream* pOutputStream) constWrites the form entity to the supplied OutputStream. |
| Methods inherited from class ot::ManagedObject |
addRef(), getRefCount(), onFinalRelease(), operator=(const ManagedObject&), release() |
| Constructor/Destructor Detail |
MultipartFormEmulator()
Field and header values containing Unicode characters that cannot be mappped into the form's encoding will have those characters silently replaced with an alternative character. If your form may contain field values whose characters cannot be represented by ISO-8859-1 then you should use the alternative constructor which allows an encoding name to be specified.
MultipartFormEmulator(const String& encoding)
The encoding parameter specifies the character encoding used when formatting field values. The encoding parameter is used internally to request a CodeConverter from the system's CodeConverterFactory. If the specified encoding is not recognized by the factory an UnsupportedEncodingException is thrown.
UnsupportedEncodingException - | Method Detail |
virtual void addField(const String& name,
const String& value)
fieldName - value - virtual void addFilenameField(const String& fieldName,
const File& file,
const String& filename,
const String& encoding,
const String& mimeType)
fieldName - file - filename - encoding - mimeType - UnsupportedOperationException - virtual void addFilenameField(const String& fieldName,
InputStream* pStream,
const String& filename,
const String& encoding,
Int64Type fileLength,
const String& mimeType)
fieldName - pStream - filename - encoding - mimeType - UnsupportedOperationException - IllegalArgumentException - virtual void clear()
static ByteString GenerateRandomSeparator(const ByteString& prefix,
size_t length)
prefix - length - IllegalArgumentException - virtual String getContentTypeHeader() const
It is advisable to use this method when constructing a HTTP request rather than assuming a constant value for the Content-Type header. One important reason for this is that the Content-Type header contains a variable separator parameter when describing the multipart/form-data encoding.
virtual RefPtr< InputStream > getEntity() const
This function can be called repeatedly, with each invocation returning a RefPtr to a new InputStream. In most cases the returned InputStream can be read without affecting the internal state of this form because it is generated from the form's field without altering their state. The notable exception to this case is when a filename field has been added using the overloaded method which takes an InputStream parameter. In this case the filename field's InputStream is returned as part of a SequenceInputStream, and this stream can be read only once. In this case, subsequent calls to this function will result in an IOException.
IOException - virtual Int64Type getEntityLength() const
const ByteString& getSeparator() const
void regenerateSeparator()
void setSeparator(const ByteString& sep)
void writeEntity(OutputStream* pOutputStream) const
pStream - IOException - NullPointerException -
|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||