0

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

  1. Client application calls API to "create" document -- Works fine.

  2. 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

  3. 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

1 Answers1

0

Not sure what you're doing here. DCTM REST will expose a direct ACS link to the content (binary) or provide you directly the file as stored in DCTM, you do not need to do anything with encoding, as you are most likely breaking the file by changing the encoding

aldago
  • 109
  • 2
  • Thanks for your response.Then i am surely doing unnecessary things. I am from client application team and i have been given to use api's as below. 1 : Create Document : POST http://host/dctm-rest/repositories/DCTM_DEV/folders/0b02f68280059e18/documents Requestbody : {"properties":{"object_name":"Vienna9.txt","r_object_type":"dm_document"}} 2 : Set contents of document: POST. https://host/dctm-rest/repositories/DCTM_DEV/objects/0902f68280062792/contents Request json body : attachmenta base64 is passed as text to Documentum API. {"attachments":"UkVRMDAKD=="} – Shrijeet Sinha Jun 17 '21 at 02:06
  • Step 3: When i fetch document ( on Postman as of now ) using GET: https://host/D2/servlet/DispatchDownload?event_name=d2_view&id=0902f68280062792&_docbase=DCTM_DEV I get same base64 string back and not actual readable contents of file. Hence i was trying to decode base64 contents. Can you may be share the API to pass both in one API. – Shrijeet Sinha Jun 17 '21 at 02:09
  • Why are you creating the document via REST and downloading via D2? Why don't you use the REST API to download it? Yo ucan check (Java) code in this class: https://github.com/aldago/DctmRestJava11/blob/master/es/aldago/dctm/RestOperations.java – aldago Jun 17 '21 at 16:24