Multi-Part Decoding Examples
Receiving an Uploaded File
- Recieving a file from the web browser is fairly easy. There are two steps to adding
the ability to upload a file in your web application. It requires properly formatting
the HTML to add the file element, and it requires fetching the assosicated File out of
the HTTPRequest.
- <form name="GZIPUpload"
enctype="multipart/form-data"
action="$$.ServletPath."
method=POST>
- <input type=file
name="GZIPFile">
<input type=submit
value="Test GZIP"
name="Upload">
</form>
-
As you can see the encoding type on the form the FILE element is located in set to
multi-part encoding. This is absolutely critical. If the encoding on the form is
not set to multi-part encoding only the file name will be uploaded; and not the file itself.
When the file is uploaded to Apollo, it will be decoded and stored in the HTTPRequest object
by the name of the file element. Use the getFile(String) method of the HTTPRequest object
to fetch the HTTPFile object. Each HTTPFile request object has three pieces of data in it, the
File name of the file uploaded, the Mime-type of the file uploaded, and the file data itself.
This data is set from what the browser transmits, and there is no guarantee that all three
values will be available (however all browsers seem to send all three). The mime-type
of the uploaded file is set by the browser, and not apollo. The uploaded file is stored
in memory in a String. Large ungarbage collected files may adversely effect your memory
management system; be sure to not allow lingering references so garbage collection can
function properly.
-
-
Examples from demo Site:
GZIPBroker