Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public static final class HttpServer.Part
- Object
- HttpServer.Part
One part of a
multipart/form-data request body: a form field, or an
uploaded file when it has a filename.Methods
public String getName() | The field name from its Content-Disposition, or null. |
public String getFilename() | The uploaded file’s name as the client gave it, or null for a plain field. |
public String getContentType() | The part’s Content-Type, or null when it declared none. |
public String getHeader(String headerName) | One of the part’s own headers, by a name in any case; or null. |
public int getSize() | The part’s content length in bytes, capped at Integer.MAX_VALUE; see getLength for a part that may be larger. |
public long getLength() | The part’s content length in bytes. |
public InputStream getInputStream() | The part’s content as a stream, which is how to read a large upload: a part of a body that was spooled to disk is read from the spool file, never brought into memory whole. |
public byte[] getBytes() | The part’s content. |
public String getText() | The part’s content as UTF-8 text. |
Inherited methods
Method details
getName
public String getName()The field name from its Content-Disposition, or null.
getFilename
public String getFilename()The uploaded file’s name as the client gave it, or null for a plain
field. Never use it as a path: it is whatever the client sent.
getContentType
public String getContentType()The part’s Content-Type, or null when it declared none.
getHeader
public String getHeader(String headerName)One of the part’s own headers, by a name in any case; or null.
getSize
public int getSize()The part’s content length in bytes, capped at
Integer.MAX_VALUE; see
getLength for a part that may be larger.getLength
public long getLength()The part’s content length in bytes.
getInputStream
public InputStream getInputStream()The part’s content as a stream, which is how to read a large upload: a
part of a body that was spooled to disk is read from the spool file,
never brought into memory whole. The stream is valid for the duration
of the request; the file is gone once the response has been sent.
getBytes
public byte[] getBytes()The part’s content. The array is the part’s; copy it to change it.
Throws
IllegalStateException- for a part larger than the server’s
in-memory body limit (
CN1_HTTP_MAX_BODY_MB), which only a spooled body can hold; read that one withgetInputStream
getText
public String getText()The part’s content as UTF-8 text. Throws IllegalStateException when it
is not valid UTF-8 – a binary upload – rather than returning
replacement characters the client never sent.