Salesforce

How Do I Add a Unicode or a UTF-8 BOM to a BLOB File? (Magic xpi 4.1)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

How Do I Add a Unicode or a UTF-8 BOM to a BLOB File? (Magic xpi 4.1)

Byte order marks (BOMs) are used to indicate the byte order of a text file. There might be occasions that you want to add a BOM to a BLOB file to help you with encoding detection. You can easily add a Unicode or a UTF-8 BOM to a BLOB file using the BlobAddBOM function.

Adding a Unicode or a UTF-8 BOM to a BLOB file using the BlobAddBOM function:

  1. For the purpose of this example, begin by creating a sample BLOB file. Save it under your <Magic xpi installation>\projects\<current project> folder. Call this file utf8.txt.

  2. Now, create the variables that you will use in this example. Open the Variable repository and, under the Flow Variable tab, create a BLOB variable called F.utf8nobom and a logical variable called F.logic.

  3. Drag a Flow Data Service into your flow.

  4. To begin the process of adding a BOM, you need to convert your chosen file to a BLOB. In the Flow Data Configuration dialog box, click New.

  5. In the Action column, select Update from the drop-down list.

  6. In the Type column, select Flow.

  7. In the Name column, select the F.utf8nobom BLOB variable that you previously created.

  8. In the Encoding column, select Binary.

  9. In the Update Expression column, click to open the Expression Editor.

  10. In the Expression Editor, enter the following expression (as shown in the image below), and then click OK:

    File2Blb (EnvVal ('currentprojectdir')&'utf8.txt')


  11. The next stage is to add a BOM to the newly-created BLOB. This is done by using the BlobAddBOM function. In the Flow Data Configuration dialog box, click New.

  12. Enter the same parameters that you entered in steps 5 to 8, above.

  13. In the Update Expression column, click to open the Expression Editor.

  14. In the Expression Editor, enter the following expression (as shown in the image below), and then click OK:

    BlobAddBOM ( F.utf8nobom ,1)

    Note:

    To add a UTF-16 BOM, use the following expression: BlobAddBOM ( F.utf8nobom ,2).



  1. Now you need to convert your BLOB with its newly-added BOM back to the original file format. You do this with the Blb2File function. In the Flow Data Configuration dialog box, click New.

  2. In the Action column, select Update from the drop-down list.

  3. In the Type column, select Flow.

  4. In the Name column, select the F.logic logical variable that you previously created.

  5. In the Update Expression column, click to open the Expression Editor.

  6. In the Expression Editor, enter the following expression (as shown in the image below), and then click OK:

    Blb2File ( F.utf8nobom , EnvVal('currentprojectdir') &'utf8withbom.txt')


  1. Click OK to close the Flow Data Service.

  2. Build your project.

  3. Now, when you debug and run your project, you will see a new .txt file in the <Magic xpi installation>\projects\<current project> folder called utf8withbom.txt. This file is your original BLOB file with its newly-added BOM. Its name is taken from the expression that you entered in step 20. You can use a Hex Editor to see the new BOM.

Related Topics

How Do I Remove a Unicode or a UTF-8 BOM from a BLOB File?

Reference
Attachment 
Attachment