Contact Us 1-800-596-4880

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

mimeType

String

The MIME type string value to transform to a MimeType.

Example

This example transforms a MIME type string value without parameters to a MimeType value.

Source

%dw 2.0
import * from dw::module::Mime
output application/json
---
fromString("application/json")

Output

{
  "success": true,
  "result": {
      "type": "application",
      "subtype": "json",
      "parameters": {}
  }
}

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")

Output

{
  "success": true,
  "result": {
      "type": "multipart",
      "subtype": "form-data",
      "parameters": {
          "boundary": "the-boundary"
      }
  }
}

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")

Output

{
  "success": false,
  "error": {
      "message": "Unable to find a sub type in `Invalid MIME type`."
  }
}