enhancement
major
minor
defect
critical
major
minor
minor
#30188
TL Script: Read a binary value as text; Read a web app resource as a binary value
Problem
Binary Value as Text
In TL-Script, there is no function that reads the contents of a binary value (BinaryData) as a string:
- toString(binary) returns the filename.
- base64Decode returns a binary value again.
- BinaryFunctions only provides contentType, size, and imageSize.
To process generated content (e.g., the SVG from reactFlowToSvg), you must therefore use the workaround via parseCSV. This workaround is prone to errors due to the built-in escape handling (\): \0 produces a NUL character, and \n/\t are converted to control characters.
Web App Resource as a Binary Value
There is also no function that reads a web app resource (e.g., a logo under /images/... or WEB-INF/...) as a binary value. This is needed, for example, for logos in server-side generated PDFs (pdfFile).
Expected
- binaryText(binary, charset: "utf-8") -> String
- webResource("/path") -> Binary (read-only, only within the web app)
Solution
binaryText(binary, charset) (in BinaryFunctions) returns the contents of a binary value as text. The bytes are decoded without any escape processing. The character set is optional: if not specified, the `charset` parameter of the binary value’s content type is used; otherwise, UTF-8 is used. If no binary value is provided, the result is null; an unknown character set results in an error message.
webResource(path) (in WebResourceFunctions, prefix web) reads a resource from the web app via the FileManager (i.e., taking into account the overlays of the fragment modules) as a binary value. The path must begin with /; paths containing .., file://, or a backslash are rejected, so that nothing outside the web app can be read. A nonexistent resource returns null. The name of the result is the filename; the Content-Type is determined from the file extension via the MimeTypesModule.
Since configuration values are stored under WEB-INF/conf, webResource is marked as @AdminOnly: In interactively entered scripts (e.g., script console), only an administrator may call the function; scripts from the application configuration (e.g., PDF generation) are not restricted.
MIME Types from the Java Runtime Environment
Previously,`MimeTypesModule.getMimeType(fileName)` only recognized the `mime-mapping` entries in the application’s ` web.xml ` and returned ` application/octet-stream ` for any extension not listed there—meaning, in applications without their own entries, this also applied to `.png`, `.svg`, .pdf. An extension without an entry (or with an “application/octet-stream” entry) is now looked up in the MIME types of the Java runtime environment (URLConnection.guessContentTypeFromName); entries in web.xml still take precedence. This benefits all areas that determine the content type from the file name ( FileManager resources, uploads, drag-and-drop, documents).