cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
alan_bloom
New Member

Problem with encoding while importing CSV attachment into Power Automate

I'm having problems automating the import of data from an attachment using Power Automate.
 

I had successful process that could fetch a CSV stored on OneDrive and separated out the data into an array, importing it into a SharePoint list. But when I modified the trigger to be When an email arrives, I get encoding issues.

 

The beginning of the process is:

When email arrives

->

Initialise empty String variable (fileContent)

->

Loop (get attachment content)

Set fileContent to attachment content (this is where encoding is off)

-->

Initialise CSV array

value = split(decodeUriComponent(replace(replace(uriComponent(variables('fileContent')),'%0D',''),'%0A','#NL#')),'#NL#')

(--> then, several additional steps that work correctly)

Screenshot2020-12-1493357.png

The complex expression in the initialisation of the CSV array is to separate the CSV file into component lines, and converting it into URI components achieved that (at least when the file was on one drive).

 

The problem I'm having is that the attachment content is being shown as if the encoding is strange. The other steps seem to be working ok but this first step is messing everything up. 

If the same CSV file is fetched from OneDrive, it worked.  But as an attachment, it's messed up.

The ContentBytes is correct - if I put that output into the base64 decoder, it's correct.

If I copy and paste the odd code in the picture and put that into a different text box, it does seem to convert it to the correct text but not quite perfectly.

I've also tried with and without the extra variable to store the content - if I reference it directly in the array set up, the result is exactly the same.

Screenshot2020-12-1493534.png

 

There doesn't seem to be anything particularly odd about the file.  It's UTF16.

I've tried additional base64, base64 to string, etc. Everything always ends up the way it is in the picture.

 

Thanks for any help you can give!

1 REPLY 1
alan_bloom
New Member

Having worked with this more, this doesn't occur with a file that isn't UTF16 encoded. But, unfortunately, this process exists because I have to work with the files that are being emailed... which are UTF16. With that in mind, is there a way to work with this file or tell P.A. which encoding it is?

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (4,400)