You need to sign in to do that
Don't have an account?

get content of .docx attachment
Hello,
I am trying get the content of the attachment using APEX.
For this I have used -
string myEncodedString = EncodingUtil.base64Encode(mailAttachment.Body);
system.debug('myEncodedString +++++++ ' + myEncodedString);
string attBody = EncodingUtil.base64Decode(myEncodedString).toString();
With this I am able get data for csv and .txt(UTF-8 enconded) file but I am not abl read the contents of .docx, .xlsx, .pdf etc
The error I get is 'BLOB is not a valid UTF-8 string'.
After a bit of research I found that, though formats like .docx are encoded in UTF-8 but they are archieved formats (similar to zip).
So can anybody help me to get the content of these formats.
Help would be appriciated.
Best,
Ritik
I am trying get the content of the attachment using APEX.
For this I have used -
string myEncodedString = EncodingUtil.base64Encode(mailAttachment.Body);
system.debug('myEncodedString +++++++ ' + myEncodedString);
string attBody = EncodingUtil.base64Decode(myEncodedString).toString();
With this I am able get data for csv and .txt(UTF-8 enconded) file but I am not abl read the contents of .docx, .xlsx, .pdf etc
The error I get is 'BLOB is not a valid UTF-8 string'.
After a bit of research I found that, though formats like .docx are encoded in UTF-8 but they are archieved formats (similar to zip).
So can anybody help me to get the content of these formats.
Help would be appriciated.
Best,
Ritik
[1] https://developer.salesforce.com/forums/?id=906F0000000AYFTIA4
I had already tried this solution, but I am getting only special characters in it (similar to Firoz Khan in the link pprovided by you).
Best,
Ritik