Salesforce

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

« Go Back

Information

 
Created BySalesforce Service User
Approval Process StatusPublished
Objective
Description

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

If you need to remove a Unicode or a UTF-8 BOM from a binary BLOB file, you can use the BlobRemoveBOM function.

Removing a Unicode or a UTF-8 BOM from a binary BLOB file using the BlobRemoveBOM function:

  1. For the purpose of this example, begin by creating a sample BLOB file containing a BOM. 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 two BLOB variables called F.utf8 and F.utf8nobom. Then, create a logical variable called F.logic.

  4. Drag a Flow Data utility into your flow.

  5. To begin the process of removing a BOM, you need to load the sample file into a BLOB using the File2Blb function. 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.utf8 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 remove the BOM contained in the newly-created file. This is done by using the BlobRemoveBOM function. In the Flow Data Configuration dialog box, click Add.

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

  14. In the Type column, select Flow.

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

  16. In the Encoding column, select Binary.

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

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

    BlobRemoveBOM ( F.utf8 )


  19. Now you need to load your BLOB, with its BOM removed, into a file. You do this with the Blb2File function. In the Flow Data Configuration dialog box, click Add.

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

  21. In the Type column, select Flow.

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

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

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

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


  25. Click OK to close the Flow Data utility.

  26. Build your project.

  27. 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 utf8withoutbom.txt. This file is the original file, now minus its BOM. Its name is taken from the expression that you entered in step 23. You can use a Hex Editor to verify that the BOM has been removed.

Related Topics

How Do I Add a Unicode or a UTF-8 BOM to a BLOB File?

Reference
Attachment 
Attachment