Question

Provide a document downloadable link/direct download option for documents stored in Amazon S3 webstorage

We have a requirement to provide a downloadable link for the attachments uploaded in the work objects. Downloadable link needs to be provided as a REST service response which is exposed by Pega. As documents are stored in Amazon S3 there is no direct download link to documents without logging into pega. Below is the sample document location:

file://pegacloudfilestorage:/attachments/sample_CNR-10074.pdf

Also tried the direct download option by using sendFile() api but this works when service executed from Pega standalone. When we call the service from postman/SOAP UI, document download pop-up appears but there is no content and documents are getting corrupted.

Used below java in service activity to Service activity is

try

{

String fileSpec = myStepPage.getString("spec");

PRFile remoteFile = new PRFile(fileSpec);

tools.sendFile( remoteFile, false, null, true );

}

catch ( Exception e ) {

throw new PRRuntimeException(e);

}

Requesting inputs if anyone has come across this requirement.

Thanks,

Bharatesh

Comments

Keep up to date on this post and subscribe to comments

Pega
October 1, 2018 - 3:52am

Hi Bharatesh,

 

Could you please let 's know if you are working in Pega Cloud and which version of Pega have you installed?

Regards,

Jakub

 

October 1, 2018 - 8:15pm
Response to Jakub

Yes Jakub, we are working on Pega cloud and version is Pega 7.3.1

Bharatesh

November 5, 2018 - 9:19pm
Response to CHOUGALB

Hi Bharatesh,

 

we have similar requirement and similar issue, Is your issue fixed? could you please share the approach.

Many Thanks

November 13, 2018 - 8:57am
Response to BharathD6434

Below java is used to read the file from webstorage:

try {
    String fileSpec = tools.getParamValue("DocLocation");
    ClipboardPage streampage = tools.findPage("Test");
    tools.putParamValue("fileSpec", fileSpec);
    PRFile remoteFile = new PRFile(fileSpec);
    PRInputStream pris = new PRInputStream(remoteFile);
    int len;
    byte[] buffer = new byte[1024];
    java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();

    while ((len = pris.read(buffer)) != -1) {
      os.write(buffer, 0, len);    
    }
     streampage.putObject("StreamContent", os.toByteArray());
    pris.close();
} catch (Exception e) {
    throw new PRRuntimeException(e);
}

 

Set these on service page after the java step:

.ContentType = @pxGetMimetypeFromFileName(Param.documentId)

.ContentDisposition = "form-data;filename=\""+Param.documentId+"\""