Question
Merative
US
Last activity: 16 Apr 2024 12:55 EDT
Validate a zip file uploaded using Attach content control
Hi, We are using PEGA Attachcontent control to upload a zip file using pzAttachingScreen section. To validate whether the uploaded file is zip, we are checking whether the file type is zip of not. However, we need to check if the file is an actual zip file beyond checking the file type.
For example, if an HTML or exe file type is changed to zip, and uploaded, our application would accept since the file type is ".zip".
We are exploring the way of reading Magic number to check if its a valid zip file. Does anyone have experience with this? To achieve this, we need a java file instance that refers to the zip file uploaded to the serviceexportdirectory (file://web:/StaticContent/global/ServiceExport/Test_Sheet.zip)
https://coderanch.com/t/381509/java/check-file-zip-file-java
FilePath = pega.getStaticContentUtils().getServiceExportRoot(); FileName = FilePath+myStepPage.getProperty("pyFileName").getStringValue(); java.io.File file = new java.io.File(FileName);
java.io.RandomAccessFile raf = new java.io.RandomAccessFile(file, "r"); MagicNumber = String.valueOf(raf.readInt());
This always errors out saying file or directory is not valid.
PRFile file1 = new PRFile(FileName); works fine and able to read the file. But I cannot pass file1 to new java.io.RandomAccessFile(file1, "r");