I am trying below work related to Documentum REST API calls. I believe issue is more towards decoding base64. I think so...
Client application - > Documentum API call to save document
Client application calls API to "create" document -- Works fine.
Client application then calls another API to set contents of file created in step 1. Document contents is sent as "base64" formatted string (eg - UkVRMDA3NTYwOC8gQ0hHMDA0MDkzNyAgLSB==) to Documentum API - Works fine
Client application fetch document from another API and gets back document with same contents as "base64" formatted string. - Works fine
Now , on step 3 , when i have to fetch document, i want contents to be returned back in utf-8. I tried to decode contents of file ( base64 formatted string) to utf-8 readable format ( format which is actual file content before encoding to base64).
I tried below code as "Test" scripts on Postman and I am not getting any error as such on Postman console.
var CryptoJS = require("crypto-js");
var plainText=pm.response.json().attachments; \\ Taking json response of API call
//console.log(plainText); \\Gives back base64 formatted which was set as document contents
intermediate = CryptoJS.enc.Base64.parse(plainText); \\Doing parse
var response_txt = CryptoJS.enc.Utf8.parse(intermediate).toString(); \\Changing to utf-8
console.log(response_txt);
When i do "Send and Download" on Postman , file is getting downloaded but when i open document I get below error. "Adobe Acrobat could not open document because it is either not supported file type or file has been damaged (...and wasnt correctly decoded)"
I am not getting what i am doing wrong. [1]: https://i.stack.imgur.com/FqGP7.png
All I want is when I do fetch document api call to Documentum , I want document to be returned in readable format.
I need guidance like: Is issue on js script ( as shown above) to decode contents on Postman ? OR Is there anything separate I need to do when doing API call to Documentum ?
Thanks