This function returns the content of the specified file as a BLOB (binary large object) of type xs:base64Binary. Note that even though the data type is called "base64Binary", the internal representation is just a BLOB. Only when you map the function's result to an XML node of type xs:base64Binary will it actually be base64-encoded. You could also map the function's result to xs:hexBinary, to a database blob, or to a binary field in a Protocol Buffers structure.
To read a binary file into a mapping, supply its path as input to the filepath argument. If the filepath is relative, then MapForce will look for the file in the same directory as the mapping. The must-exist argument is optional; if the file cannot be opened and this parameter is true, the mapping throws an error. If the file cannot be opened and this parameter is false, an empty binary is returned.
The file path.
Optional parameter. If the file cannot be opened and this parameter is true, the mapping throws an error. If the file cannot be opened and this parameter is false, an empty binary is returned.
The default value is true.
The mapping illustrated below reads data from an image file and writes it to a database table. The target database is SQLite. Notice that the data type of the picture database field is BLOB.
To extract binary content from the file, the read-binary-file function was used. In this example, the first argument, filepath, is supplied by a constant. Note that, because the path is relative, MapForce will look for the image file in the same directory as the mapping.
The mapping populates the following fields in the target database:
•id - In this example, the database component is configured so that id is database-generated rather than being supplied by the mapping. For more information, see Inserting Data into a Table.
•title - This value is provided by a simple input component with the same name. Note that a design-time execution value is set ("product1") in order to make it possible to preview the mapping. For more information, see Supplying Parameters to the Mapping.
•picture - This field receives the direct output of the read-binary-file function.
Because the target component is a database, previewing the mapping generates a pseudo-SQL script that you can review, but does not send any changes to the database. To run the actual script against the database, select the menu command Output | Run SQL-Script.