Salesforce

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

« Go Back

Information

 
Created BySalesforce Service User
Approval Process StatusPublished
Objective
Description

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

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 <My Documents>\Magic\projects\<current project> folder. Call this file utf8.txt.

  2. To create the variables that you will use in this example, open the Flow Variables repository.

  3. There, create a BLOB variable called F.utf8nobom and a logical variable called F.logic.

  4. Drag a Flow Data utility into your flow.

  5. 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 Add.

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

  7. In the Type column, select Flow.

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

  9. In the Encoding column, select Binary.

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

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

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


  12. 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 Add.

  13. Enter the same parameters that you entered in steps 6 to 9, above.

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

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

    BlobAddBOM ( F.utf8nobom ,1)

    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 Add.

  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 utility.

  2. Build your project.

  3. Now, when you debug and run your project, you will see a new .txt file in the <My Documents>\Magic\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