Salesforce

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

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

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

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 <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 two BLOB variables called F.utf8 and F.utf8nobom. Then, create a logical variable called F.logic under the same tab.

  3. Drag a Flow Data Service into your flow.

  4. 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 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.utf8 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 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 New.

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

  13. In the Type column, select Flow.

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

  15. In the Encoding column, select Binary.

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

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

    BlobRemoveBOM ( F.utf8 )


  18. 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 New.

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

  20. In the Type column, select Flow.

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

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

  23. 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')


  24. Click OK to close the Flow Data Service.

  25. Build your project.

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