Question
Evonsys (PVT) LTD
LK
Last activity: 8 Jan 2025 10:45 EST
How to get pyAttachStream data when using Filepath Controller ?
Hi team,
In our application we have used FilePath controller to attached document, I need to know where to store pyAttachStream data after upload data in to filepath controller ?
thank you.
Eranda.
-
Reply
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Updated: 8 Jan 2025 10:45 EST
HCA Healthcare
US
@Eranda10274 yes you can convert a file path into a file stream in Pega. You can create a custom activity using a Java step. The activity should read the file from the given path using java.io.FileInputStream
. The file content can then be converted into a Base64 string using java.util.Base64.getEncoder().encodeToString()
. Once the file content is converted, store the Base64 string in a clipboard property like pyAttachStream
for further use. Make sure the file path is accessible and valid to avoid errors during the conversion process. After running the activity, check the clipboard to verify if the pyAttachStream
property holds the file data correctly. If you only need to store the file content temporarily, avoid saving it directly in the work object and consider saving it in a separate data class. This approach ensures the file content is properly converted and available for processing in your Pega application
HCA Healthcare
US
@Eranda10274 When using the FilePath Controller in Pega to upload a document, the pyAttachStream
(which stores the file content) is available on the pxRequestor.pyFileUpload
page after the file is uploaded. To store this data, you can create a new Data-WorkAttach-File
instance and set the pyAttachStream
along with other details like pyFileName
and pyNote
. Save this instance using an Obj-Save step in an activity. Avoid storing large files directly in the work object to prevent performance issues. Instead, store the file in a separate data class and reference it in the work object using a link or identifier. If the file needs to be retained for reporting or long-term storage, you can also use external storage like a content management system. This approach ensures better performance, easy data retrieval, and proper file management in your Pega application
Evonsys (PVT) LTD
LK
hi @Sairohith , thank you for answering my question. on the clipboard pxRequestor.pyFileUpload this value was empty, do you have any idea about that.
HCA Healthcare
US
@Eranda10274If the pxRequestor.pyFileUpload
page is empty after using the FilePath Controller in Pega, it means the file data is not automatically captured in the clipboard. The FilePath Controller only references the file location, not the content, so you need to handle the data capture manually. To fix this, configure a post-upload event like a data transform or activity to read the file from the specified path and convert it into a Base64 string for storage in pyAttachStream
. You can use the FileListener
or a custom activity to fetch the file content using the file path stored in the FilePath Controller. Also, ensure the correct security settings are applied, such as checking attachment type restrictions in the Application Rule and Dynamic System Settings (DSS). If you need to store the actual file data in the clipboard for further processing, consider using the File Upload control instead, which automatically captures the pyAttachStream
. This approach ensures proper file handling and storage in your Pega application
Evonsys (PVT) LTD
LK
@Sairohith After few configuration, I was able to get pxRequestor.pyFileUpload value. but not store file content
Using this file path can we convert into filestream.
Thank you,
Eranda.
Accepted Solution
Updated: 8 Jan 2025 10:45 EST
HCA Healthcare
US
@Eranda10274 yes you can convert a file path into a file stream in Pega. You can create a custom activity using a Java step. The activity should read the file from the given path using java.io.FileInputStream
. The file content can then be converted into a Base64 string using java.util.Base64.getEncoder().encodeToString()
. Once the file content is converted, store the Base64 string in a clipboard property like pyAttachStream
for further use. Make sure the file path is accessible and valid to avoid errors during the conversion process. After running the activity, check the clipboard to verify if the pyAttachStream
property holds the file data correctly. If you only need to store the file content temporarily, avoid saving it directly in the work object and consider saving it in a separate data class. This approach ensures the file content is properly converted and available for processing in your Pega application
Updated: 8 Jan 2025 10:45 EST
Evonsys (PVT) LTD
LK
Hi @Sairohith,
try {
String strAttachStream = null;
String strAttachName = null;
java.io.InputStream attachInputStream = null;
boolean streamBasedUpload = false;
boolean set = false;
String pathOnServer = "" ;
if(!exitActivity)
{
/* Standard Browse File Upload */
if (!set) {
boolean isFileTypeImage = false;
ClipboardPage pgRequestorPage = tools.getRequestor().getRequestorPage();
String strFileName = pega_rules_utilities.pzGetUploadedFileName(pgRequestorPage);
int lio = strFileName.lastIndexOf("/") + 1;
String fName = StringUtils.encodeCrossOSString(strFileName.substring(lio, strFileName.length()));
lio = fName.lastIndexOf(".");
if(lio != -1)
{
String fileType = fName.substring(lio + 1);
Hi @Sairohith,
try {
String strAttachStream = null;
String strAttachName = null;
java.io.InputStream attachInputStream = null;
boolean streamBasedUpload = false;
boolean set = false;
String pathOnServer = "" ;
if(!exitActivity)
{
/* Standard Browse File Upload */
if (!set) {
boolean isFileTypeImage = false;
ClipboardPage pgRequestorPage = tools.getRequestor().getRequestorPage();
String strFileName = pega_rules_utilities.pzGetUploadedFileName(pgRequestorPage);
int lio = strFileName.lastIndexOf("/") + 1;
String fName = StringUtils.encodeCrossOSString(strFileName.substring(lio, strFileName.length()));
lio = fName.lastIndexOf(".");
if(lio != -1)
{
String fileType = fName.substring(lio + 1);
isFileTypeImage = fileType.matches("(?i)jpg|jpeg|png|gif|bmp|pdf");
}
java.util.HashMap hmFileInfo = pega_rules_utilities.pxUploadFile(true, isFileTypeImage);
Boolean streamBasedUploadObj = (Boolean) (hmFileInfo.get("IsStreamProvided"));
streamBasedUpload = streamBasedUploadObj == null ? false : streamBasedUploadObj;
if(streamBasedUpload)
{
attachInputStream = (java.io.InputStream) hmFileInfo.get("FileInputStream");
}
else
{
strAttachStream = (String)hmFileInfo.get("FileData");
}
strAttachName = (String)hmFileInfo.get("FileName");
pathOnServer = (String)hmFileInfo.get("FilePathOnServer");
}
String strECMAttachmentName = tools.getParamValue("ecmFileName");
if(strECMAttachmentName.length() > 0) {
strAttachName = strECMAttachmentName;
}
/* Fail */
if ((!streamBasedUpload && (strAttachStream == null || strAttachName == null) ||
(streamBasedUpload && attachInputStream == null)))
{
pega.terminateActivity();
}
ClipboardPage cpNFAttach = tools.findPage("NewFileAttachment", false);
cpNFAttach.putString("pyAttachStream", strAttachStream);
cpNFAttach.putString("pxAttachName", strAttachName);
cpNFAttach.getProperty("pyAttachInputStream").setValue(attachInputStream);
cpNFAttach.getProperty("pyIsStreamBasedUpload").setValue(streamBasedUpload);
cpNFAttach.getProperty("pyFilePath").setValue( pathOnServer );
cpNFAttach.putString("pyNote", tools.getParamValue("pyNote"));
}
} catch (PRRuntimeException ex) {
tools.getThread().getThreadPage().putString("pyXMLStream", " ");
myStepPage.addMessage("pyUploadFailAsFileDoesntExists");
pega.terminateActivity();
}
After Adding this java code, we can encode Attachment data. and store attachment data into NewFileAttachment page. (here exitActivity is local paramiter)
Thank you for your Instruction. now attachment save on the Data-WorkAttache-File class data table. without Work object class refer.