Question
HCL
NL
Last activity: 8 Mar 2017 10:45 EST
How can i get the absolute file path for a file uploaded using "pzMultiDragDropControlStandard" control?
I have a requirement, where I need to use the OOTB Drag & Drop control. I observe that this control directly gives the base 64 encoded stream of the uploaded file and not the absolute file path.
Can anyone please help me getting the absolute file path of the file uploaded using"pzMultiDragDropControlStandard" control, as i need to parse the file after being uploaded?
***Updated by moderator: Lochan to update Categories***
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Instellars
IN
Hi Radhika,
I don't think it is possible to get the absolute path in case of a drag and drop feature due to security reasons. However you can try decoding the base64 encoded stream using the Base64Decode function available in Pega and see if it helps.
HCL
NL
Hi Ajay,
Thanks for your suggestion. In a normal case, decoding the stream works fine but in my case, i am uploading an EXCEL file with extension .xls or .xlsx
so, once i get the stream, i need to convert it back to the MS Excel workbook object, as my requirement is to parse an excel sheet and read the cell value by cell address and not to iterate over each row.
Could you please help me with any solution on this?
Pegasystems Inc.
IN
Hi Radhika,
Yes. Once after you get the stream, you need to convert it back to Excel file and store it in pxServiceExportPath. Then you can call your code which parses the file from pxServiceExportPath.
To achieve this, You can find the below code which does the same what you required:
ClipboardPage cpThread = tools.getThread().getThreadPage();
ClipboardPage cpRequestor = tools.getRequestor().getRequestorPage();
ClipboardPage cpProcess = tools.findPage("pxProcess");
String exPath = cpProcess.getString("pxServiceExportPath");
Hi Radhika,
Yes. Once after you get the stream, you need to convert it back to Excel file and store it in pxServiceExportPath. Then you can call your code which parses the file from pxServiceExportPath.
To achieve this, You can find the below code which does the same what you required:
ClipboardPage cpThread = tools.getThread().getThreadPage();
ClipboardPage cpRequestor = tools.getRequestor().getRequestorPage();
ClipboardPage cpProcess = tools.findPage("pxProcess");
String exPath = cpProcess.getString("pxServiceExportPath");
String fileSource = myStepPage.getProperty("pyFileSource").getStringValue();
try{
String strFileName = myStepPage.getProperty("pyFileName").getStringValue();
if (strFileName.lastIndexOf(".")!=-1){
strFileName = strFileName.substring(0, strFileName.lastIndexOf("."));
}
String fileType = myStepPage.getProperty("pyFileType").getStringValue();
String fileType1 = "."+fileType;
byte[] decodeContent = Base64Util.decodeToByteArray(fileSource);
PROutputStream fos = new PROutputStream(exPath+strFileName+fileType1);
fos.write(decodeContent);
fos.close();
PRFile file = new PRFile(exPath+strFileName+fileType1);
if(file.exists()){
oLog.debug("File Name "+file.getName());
long size = file.length();
oLog.debug("Size of File "+file.length());
}
}catch(java.io.IOException io){
oLog.error("Caught exception trying to create a Excel File", io);
}
Before having this java code(step) in your activity, you create new page to hold certain key parameters like filename, filesource and filetype of the file which is dragged and dropped.
Please find the below screenshot for the activity steps where before java code step what to be done.
Hope this helps.
regards,
Chetan
-
Shreeram Kumar
Pegasystems Inc.
IN
In case, screenshots attached with my previous reply are not able to view. Attaching the screenshot file here.
Pegasystems Inc.
IN
Hi Radhika,
You also need to override the drag drop control. You cannot use OOTB control as it is.
Regards,
Chetan
Pegasystems Inc.
US
Radhika,
A question for you: when you say "the absolute file path" do you mean the source path of the file on the local machine or the path that the file is uploaded to?
HCL
NL
Hi Dave,
By absolute path i mean the "SERVICE EXPORT PATH" i.e. the location where the file gets uploaded.
Pegasystems Inc.
US
Hi Radhika,
I think you can use pxProcess.pxServiceExportPath for the service export path in the clipboard. Hope this might be helpful to you.
Regards
Mahesh
Pegasystems Inc.
GB
Yup: agreed - in fact you should be able to get the full _relative_ (which should be all you need) path to the file like this:
pxProcess.pxServiceExportPath + .pxAttachName
You can do this at the point just after the file has been uploaded.
For instance (I don't necessarily recommend this; but it works as an illustration); if you specialise the Activity 'CallVirusCheck', you can do something like this for instance:
Property-Set:
local.filename = pxProcess.pxServiceExportPath + .pxAttachName
Java:
PRFile file=new PRFile( filename );[do whatever you need with 'file'...]
Where 'local.filename' is specified on the Parameters tab of you activity for instance.
See Javadocs for 'PRFile' also.
Cheers
John
-
Shreeram Kumar John Pritchard-Williams