Object -
mime
:
Entity
Represents the headers and body of a message. This can be used to represent both the entity of a top level message and an entity(body part) inside of a multipart entity.
Methods
json
content.
xml
body from the entity.
byte[]
from a given entity.
mime:InvalidContentTypeError? contentType = mimeEntity.setContentType("application/json");
Parameters
- mediaType string
-
Content type, which needs to be set to the entity
-
Return Type
(InvalidContentTypeError?) ()
if successful or else anmime:InvalidContentTypeError
in case of invalid media-type
string contentType = mimeEntity.getContentType();
-
Return Type
(string) Content type as a
string
mimeEntity.setContentId("test-id");
Parameters
- contentId string
-
Content ID, which needs to be set to the entity
string contentId = mimeEntity.getContentId();
-
Return Type
(string) Content ID as a
string
mimeEntity.setContentLength(45555);
Parameters
- contentLength int
-
Content length, which needs to be set to the entity
int|error contentLength = mimeEntity.getContentLength();
-
Return Type
(int | error) Content length as an
int
or else an error in case of a failure
mimeEntity.setContentDisposition(contentDisposition);
Parameters
- contentDisposition ContentDisposition
-
Content disposition, which needs to be set to the entity
-
Return Type
(ContentDisposition) A
ContentDisposition
object
text/plain
. To send a
JSON-compatible string, set the content-type header to application/json
or use the setJsonPayload
method instead.
mimeEntity.setBody("body string");
Parameters
- entityBody string | xml | json | byte[] | ReadableByteChannel | Entity[]
-
Entity body can be of the type
string
,xml
,json
,byte[]
,io:ReadableByteChannel
, orEntity[]
.
content-type
headers
with the default content-type, which is application/octet-stream
. This default value
can be overridden by passing the content type as an optional parameter.
mimeEntity.setFileAsEntityBody("<file path>");
Parameters
- filePath string
-
Path of the file
- contentType string (default application/octet-stream)
-
Content type to be used with the payload. This is an optional parameter. The default value is
application/octet-stream
json
content. This method overrides any existing content-type
headers
with the default content-type, which is application/json
. This default value can be overridden
by passing the content type as an optional parameter.
mimeEntity.setJson({ "Hello": "World" });
Parameters
- jsonContent json
-
JSON content, which needs to be set to the entity
- contentType string (default application/json)
-
Content type to be used with the payload. This is an optional parameter. The default value is
application/json
-
Return Type
(json | ParserError) json
data extracted from the entity body or else anmime:ParserError
if the entity body is not a JSON
application/xml
. This default value can be overridden
by passing the content-type as an optional parameter.
mimeEntity.setXml(xml `<hello> world </hello>`);
Parameters
- xmlContent xml
-
XML content, which needs to be set to the entity
- contentType string (default application/xml)
-
Content type to be used with the payload. This is an optional parameter. The default value is
application/xml
xml
body from the entity.
-
Return Type
(xml | ParserError) xml
data extracted from the entity body or else anmime:ParserError
if the entity body is not an XML
text/plain
. This default value can be overridden
by passing the content type as an optional parameter.
mimeEntity.setText("Hello World");
Parameters
- textContent string
-
Text content, which needs to be set to the entity
- contentType string (default text/plain)
-
Content type to be used with the payload. This is an optional parameter. The default value is
text/plain
-
Return Type
(string | ParserError) string
data extracted from the the entity body or else anmime:ParserError
if the entity body is not text compatible
content-type
headers
with the default content-type, which is application/octet-stream
. This default value
can be overridden by passing the content type as an optional parameter.
Parameters
- blobContent byte[]
-
byte[] content that needs to be set to the entity
- contentType string (default application/octet-stream)
-
Content type to be used with the payload. This is an optional parameter. The default value is
application/octet-stream
byte[]
from a given entity. If the entity size is considerably large, consider
using the getByteChannel() method instead.
-
Return Type
(byte[] | ParserError) byte[]
data extracted from the the entity body or else amime:ParserError
in case of errors
application/octet-stream
. This default value
can be overridden by passing the content-type as an optional parameter.
Parameters
- byteChannel ReadableByteChannel
-
Byte channel, which needs to be set to the entity
- contentType string (default application/octet-stream)
-
Content-type to be used with the payload. This is an optional parameter. The
application/octet-stream
is the default value
-
Return Type
(ReadableByteChannel | ParserError) An
io:ReadableByteChannel
or else amime:ParserError
record will be returned in case of errors
-
Return Type
(Entity[] | ParserError) An array of body parts(
Entity[]
) extracted from the entity body or else amime:ParserError
if the entity body is not a set of the body parts
-
Return Type
(ReadableByteChannel | ParserError) Body parts as a byte channel
content-type
headers
with the default multipart/form-data
content-type. The default multipart/form-data
value can be overridden
by passing the content type as an optional parameter.
Parameters
- bodyParts Entity[]
-
Body parts, which needs to be set to the entity
- contentType string (default multipart/form-data)
-
Content-type to be used with the payload. This is an optional parameter. The default value is
multipart/form-data
.
string headerName = mimeEntity.getHeader(mime:CONTENT_LENGTH);
Parameters
- headerName string
-
Header name
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Position of the header as an optional parameter
-
Return Type
(string) Header value associated with the given header name as a
string
. If multiple header values are present, then the first value is returned. An exception is thrown if no header is found. UseEntity.hasHeader()
beforehand to check the existence of a header
Parameters
- headerName string
-
Header name
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Position of the header as an optional parameter. If the position is
mime:TRAILING
, the body of theEntity
must be accessed initially
-
Return Type
(string[]) All the header values associated with the given header name as a
string[]
. Panics if no header is found. Use theEntity.hasHeader()
beforehand to check the existence of a header
string[] headerNames = mimeEntity.getHeaderNames();
Parameters
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Position of the header as an optional parameter
-
Return Type
(string[]) All header names as a
string[]
mimeEntity.addHeader("custom-header", "header-value");
Parameters
- headerName string
-
Header name
- headerValue string
-
The header value to be added
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Position of the header as an optional parameter
mimeEntity.setHeader("custom-header", "header-value");
Parameters
- headerName string
-
Header name
- headerValue string
-
Header value
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Position of the header as an optional parameter
Parameters
- headerName string
-
Header name
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Position of the header as an optional parameter. If the position is
mime:TRAILING
, the body of theEntity
must be accessed initially.
Parameters
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Position of the header as an optional parameter. If the position is
mime:TRAILING
, the body of theEntity
must be accessed initially.
Parameters
- headerName string
-
Header name
- position HeaderPosition (default <(leading|trailing)> <leading> leading)
-
Position of the header as an optional parameter. If the position is
mime:TRAILING
, the body of theEntity
must be accessed initially.
-
Return Type
(boolean) true
if the specified header key exists