text attachment fails to encode when saved to case

Hi, I have a requirement to generate a text document from case data and attach this to the case. The attachment is to be emailed.

The problem is, the contents of the file are garbled when the file is saved. I can view the .pyAttachStream content for the attachment (Data-WorkAttach-File) on clipboard and in the Tracer - this is fine. The problem seems to be happening when the attachment gets saved.

Is there an additional setting I need to ensure the right encoding?

Problem solved - I needed to use the @Base64Encode function before saving the file

@Base64Encode(StringToEncode)