To work with the content of documents, you can use the ECMContentStream data type to wrap a content stream and return information about the stream. A content stream is a stream of data that contains the content of a document, such as a word processing document or an image.
Information about these operations is found in the topic Data mapping in Enterprise Content Management operations.
The properties for the ECMContentStream data type are described in the following table:
| Property name | Description |
|---|---|
| contentLength | The length of the original (non-encoded) content length in bytes. If the property is set, the length must be a positive number. If the length is unknown, the property must not be set. |
| mimeType | The MIME media type of the content stream. For the primary content of a document, the MIME media type should match the value of the property cmis:contentStreamMimeType. For example, application/pdf. |
| fileName | The file name of the content stream. For the primary content of a document, the file name should match the value of the property cmis:contentStreamFileName. |
| content | The value of the document. It must be of type String Base64 and encoded in UTF-8. |
// Script sample code to set and encode the document content
var value = "abc";
var bytesValue = new Packages.java.lang.String(value).getBytes("UTF-8");
var content64 = Packages.org.apache.commons.codec.binary.Base64.encodeBase64(bytesValue);
tw.local.contentStream = new tw.object.ECMContentStream();
tw.local.contentStream.contentLength = value.length;
tw.local.contentStream.mimeType = "text/plain";
tw.local.contentStream.content = new Packages.java.lang.String(content64, "UTF-8");
// Script sample code to get and decode the document content
var byteValue = Packages.java.lang.String(tw.local.contentStream.content).getBytes();
var content64 = Packages.org.apache.commons.codec.binary.Base64.decodeBase64(byteValue);
var value = new java.lang.String(content64, "UTF-8");