Mulesoft SFTP write .csv file encoded UTF-8 with BOM - utf-8

I have the requirement to store a csv file with the SFTP write processor from Mulesoft on an SFTP server.
File format: CSV (comma as separator), UTF-8 with BOM
In a "transform message" I transform the JSON payload into application / csv encoding = "UTF-8"
That works great, the csv is then available on the SFTP server in utf-8 format.
%dw 2.0
output application/csv encoding="UTF8"
---
payload.data
My problem is how can I attach the BOM to the file?

Before you write the data to SFTP create a variable called utf8BOM using the dataweave below:
%dw 2.0
import * from dw::core::Binaries
output application/java
---
fromHex("EFBBBF")
Then create your new file using a write connector and write the variable above first: e.g. in the content put
vars.utf8BOM
Then write your content to the same file using append on the write connector.
This should output a UTF8 CSV file with the BOM bytes.

Related

How to parse the apparmor's raw_data file

I have a apparmor's raw_data file in linux. When open it using the 010editor, some of the content is compressed. How to parse it into a complete policy file which human can read?

How do I create a text file with Windows-1251 encoding in Lua?

I use io.open(somepath,"w"), it creates txt file in UTF-8 encoding, how do I change it to Windows-1251?

Converting logs to JSON format

klog.Info("kube config file loaded ")
is there a way to convert logs to JSON format in Go?
I tried ,
klog.info(json.Marshal("kube config file loaded"))
but did not got output in json.help me out
Klog doesnt support json formatting

RL0 file format

What is a .rl0 file format and how to access its data?
I have been searching for RL0 file format but what I get is r10 and rlo file format and I am unable to get the data inside the file.
How to get the data inside the file?
It is in hex format you can use the following code.
import binascii
with open (final_name, "rb") as myfile:
header=myfile.read()
header = str(binascii.hexlify(header))[2:-1]
print(header)

Using PHPEXCEL with UTF-8 results in error messages

When I create an Excel Sheet with PHPEXCEL based on the "01simple-download-xlsx.php" example, I will get an error message in Excel as I am using UTF-8.
The error message says "Excel cannot open the file because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file." I've used the 01simple-download-xlsx.php Testfile and tried to change the $objWriter to the one out of the 26utf8.php Testfile... both didnt work...
So how can I prevent this error and create a proper UTF-8 compatible Excel file with PHPEXCEL?
The reason was:
I have saved my php files with notepad in UTF-8 format. Therefor it was saved with the UTF-8 BOM. I have reopened the files in Notepad++ and saved the files as UTF-8 Without BOM. This way the Excel file gets generated correctly.

Resources