Altova MapForce 2025 Enterprise Edition

This function writes binary content to the specified file path and returns the path of the written file. If a binary file is the only desired output, connect the function's result to a simple output component. Because this function writes a file whenever its output is used in the mapping, it is recommended to connect the function's result directly to a target component, without using other processing in between.

mf-func-write-binary-file

To write binary files, supply their path as input to the filepath argument. If filepath is relative, then MapForce will generate the file in the same directory as the mapping. The content argument must be connected to the actual binary content (for example, a BLOB field in a database).

 

When you preview the mapping in MapForce, the function generates temporary files by default, instead of writing files directly to the disk. To save the temporary files to disk, first click the Output pane, and then click the Save generated output ic-save-sel-string or Save all generated outputs ic-save-all-out toolbar button, as applicable.

 

To configure MapForce to write output directly to final files instead of temporary, select the Tools | Options menu command, click General, and then select the Write directly to final output files option. Be aware that this option overwrites any existing files with the same name.

 

The function always returns the final (not temporary) file name, even when the final file is not saved to the disk yet (that is the case when you preview the mapping and the Write directly to final output files option is disabled).

 

Note that it is not supported for a mapping to read back its own output file.

 

Languages

Built-In

 

Parameters

Name

Type

Description

filepath

xs:string

The input file path.

content

xs:base64Binary

The binary content of type xs:base64Binary.

 

Example

The mapping illustrated below reads BLOB values from a SQLite database and writes image files to the disk. The database has a table called products, which has the following columns (fields):

 

id (integer, the unique permanent serial number of the record)

title (text, the title of the product)

description (text, the product's description)

picture (blob, the product's image)

 

For the scope of this example, only the id and picture fields are relevant.

mf-func-write-binary-file_example1

The goal of the mapping is to extract all pictures from the products table and write them as files to the disk. As illustrated above, the write-binary-file function is used for that purpose. The first argument, filepath, receives the file path for each image. The path must be unique to avoid overriding any files, so it is generated by concatenating the unique database id of each record with the word "image" and then adding the ".png" file extension (it is assumed that all pictures are in PNG format). Note that the path is relative, so the files will be written to the same directory as the mapping.

 

The second argument, content, receives the binary content stored in the database.

 

The count function returns a count of all generated files, and combines this number with the string "file(s) written". This provides a report as to how many files were actually generated by the mapping. In this example, the database contains only two product records, so the mapping output reflects this:

mf-func-write-binary-file_example2

As stated previously, this function generates temporary files when the mapping runs in preview execution. To preview each individual file, use the arrow buttons to navigate to the record of interest, click the Open with button, and select an image editor.

mf-func-write-binary-file_example3

To save all files, click the Save generated output ic-save-sel-string or Save all generated outputs ic-save-all-out toolbar button, as applicable.

 

© 2018-2024 Altova GmbH