Question
Vishnu Institute Of Technology
Vishnu Institute Of Technology
IN
Vishnu Institute Of Technology
Posted: May 22, 2024
Last activity: May 22, 2024
Last activity: 22 May 2024 10:44 EDT
Solved
Download Binary stream content
How to download Binary stream content I have a requirement to decode the binary stream data
***Edited by Moderator Rupashree S. to add Capability tags***
To see attachments, please log in.
Hi @PenumarthiM for downloading the binary stream content, have to create a function for the java code, where we need to pass the parameters like fileType, fileName, fileContent, persistFileToServiceExport as per your requirement. you can the use the below code for your reference, this code will be used to decode the binary stream data and will be send to the browser for download.
PublicAPI tools=ThreadContainer.get().getPublicAPI(); boolean isFileDownloaded = false; ByteArrayOutputStream pdfoutStream = new ByteArrayOutputStream(); if(fileName.trim().length() == 0){ fileName = "Sample"; // If fileName is not passed setting it to sample } if(fileType.trim().length() ==0){ fileType = "pdf"; // If fileType is not passed setting it to pdf }
Hi @PenumarthiM for downloading the binary stream content, have to create a function for the java code, where we need to pass the parameters like fileType, fileName, fileContent, persistFileToServiceExport as per your requirement. you can the use the below code for your reference, this code will be used to decode the binary stream data and will be send to the browser for download.
PublicAPI tools=ThreadContainer.get().getPublicAPI(); boolean isFileDownloaded = false; ByteArrayOutputStream pdfoutStream = new ByteArrayOutputStream(); if(fileName.trim().length() == 0){ fileName = "Sample"; // If fileName is not passed setting it to sample } if(fileType.trim().length() ==0){ fileType = "pdf"; // If fileType is not passed setting it to pdf }
if(fileContent != null && fileContent.trim().length()>0){ try{ byte[] pdfBytes = pdfoutStream.toByteArray(); byte[] byteStream = Base64Util.decodeToByteArray(fileContent); //decoding binary stream which was encoded tools.sendFile(byteStream,fileName+"."+fileType,persistFileToServiceExport, null,true); //sending stream content to browser if(isFileDownloaded){ tools.sendFile(pdfBytes,fileName,false, null,isFileDownloaded); }else{ tools.getParameterPage().putObject("pdfByteArrayObj",byteStream); } }catch(Exception ex){ pega_rules_default.pxLogMessage("Exception while downloading the engine. Details are:"+ex); return isFileDownloaded; } } return isFileDownloaded;