Question

How to download a file( binary stream) received from external system REST Service response in Pega application

We have a requirement to search and download a document/file from an external system which exposed a REST API.

In pega(v7.1.7), we have created a CONNECT-REST to call this REST API and tried to access document from external system. We are able to search the documents Metadata( which is in JSON format) by mapping response to JSON.

But we are not able to download the file when tried the appropriate download function of externa API. However if we try the external API download URL in broswer it prompt the file download option.

We need the same(download prompt) from Pega screen, while user take download action and pega calls external download API via CONNECT-REST.

Does any body implement this with CONNECT-REST? Please suggest any way to solve this problem.

Thanks & Regards,

Yuvraj Joshi

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

October 25, 2016 - 10:49am

Further update - able to get the file content( binary stream) in a response property of type string.

But thats still not readable. Main question still open - How to get a prompt to download a file on pega screen.

Appriciate any response. Thanks in Advance.

Pega
November 8, 2016 - 5:45am
Response to YUVRAJ10-1

You can use similar to below piece of code to write the binary stream content to file in an activity java step,Once you have file ready, you can invoke DownloadFile OOB Activity to download the file.

 f= new java.io.File(FullPath+pdfName);
      fileOuputStream = new java.io.FileOutputStream(f);
      fileOuputStream.write(byteArray);
      fileOuputStream.close();

November 8, 2016 - 3:22am

I hope you have to use java activity to download the file once you have recived the file location url from the REST service. 

November 8, 2016 - 3:55am

Yeah, I think, by using PublicAPI.sendFile() in an activity to send the file content will prompt for download dialog at client. For more details, please refer EngineAPI documentation available in DesignerStudio.

Pega
November 8, 2016 - 5:47am
Response to ChandraSekharBk

Also : take a look at the Out-Of-Box Activity 'Code-Pega-PDF.View' : which streams a PDF (from a byte[] array) back to the browser.

If you have already captured the binary file in a 'byte[]' array; you should be able to use the same API (sendFile) to 'resend' the data back to the client.

 

Pega
November 8, 2016 - 4:23am

you can capture the response url of metadata and use 'Open URL in window' action on click event of any button or link. Or you can write a similar activity as 'DownloadFile' which will download the file from service export location.