%dw 2.0
import * from dw::module::Mime
output application/json
---
fromString("application/json")
DataWeave
fromString
fromString(mimeType: String): Result<MimeType, MimeTypeError>
Transforms a MIME type string value representation to a MimeType
.
Introduced in DataWeave version 2.7.0.
Parameters
Name | Type | Description |
---|---|---|
|
String |
The MIME type string value to transform to a |
Example
This example transforms a MIME type string value without parameters
to a MimeType
value.
Source
Output
{
"success": true,
"result": {
"type": "application",
"subtype": "json",
"parameters": {}
}
}
Json
Example
This example transforms a MIME type string value that includes a parameters
to a MimeType
value.
Source
%dw 2.0
import * from dw::module::Mime
output application/json
---
fromString("multipart/form-data; boundary=the-boundary")
DataWeave
Output
{
"success": true,
"result": {
"type": "multipart",
"subtype": "form-data",
"parameters": {
"boundary": "the-boundary"
}
}
}
Json
Example
This example transforms an invalid MIME type string value.
Source
%dw 2.0
import * from dw::module::Mime
output application/json
---
fromString("Invalid MIME type")
DataWeave
Output
{
"success": false,
"error": {
"message": "Unable to find a sub type in `Invalid MIME type`."
}
}
Json