You can use BlobToBase64 in OCL to convert a single Blob (binary) value to a Base64-encoded string, for example when you need to handle binary content as text.
Syntax
blobValue.BlobToBase64
The operator is evaluated on one Blob value and returns one string.
| Input | Expression | Result |
|---|---|---|
| One Blob value | blobValue.BlobToBase64
|
One Base64-encoded string |
Convert one Blob
Use BlobToBase64 directly when your expression resolves to one object and one Blob attribute.
Customer.allInstances()->first().ProfilePicture.BlobToBase64
In this example:
Customer.allInstances()produces a collection ofCustomerobjects.first()selects one Customer from that collection.ProfilePictureis the selected customer's Blob attribute.BlobToBase64converts that Blob value to one Base64 string.
The result is a single string, not a collection.
Choose the object deliberately
first() is appropriate only when any one object is sufficient for the expression you are testing. If you need the picture for a particular customer, make the expression resolve to that customer before calling BlobToBase64. Do not treat first() as a way to identify a specific customer.
Convert a collection of Blobs
You cannot apply BlobToBase64 to the Customer collection itself. Use collect to evaluate the conversion once for each Customer.
Customer.allInstances()->collect(x | x.ProfilePicture.BlobToBase64)
In this example, collect iterates over every Customer. For each Customer, it converts ProfilePicture to Base64. The result is a new collection containing one Base64 string for each converted Blob.
| Requirement | Pattern | Result shape |
|---|---|---|
| Convert the Blob from one selected object | object.BlobAttribute.BlobToBase64
|
One string |
| Convert the Blob from every object in a collection | x.BlobAttribute.BlobToBase64) | Collection of strings |
Use the Base64 result
Base64 represents binary content as a string. Use the returned string where an expression requires text. To convert Base64 text back to a Blob, use Base64ToBlob. To create Base64 from string content rather than from a Blob, see StringToBase64.
For a compression workflow, SysSingleton.Deflate accepts and returns Blob values; convert the resulting Blob with BlobToBase64 when you need a Base64 string.
