Corrupt PDFs
Wednesday, March 3, 2021 at 01:26pmWe are seeing rare instances where downloaded PDFs from OneSpan are corrupted. We are using Java SDK. Are there previous examples of this and fixes?
Thanks.
We are seeing rare instances where downloaded PDFs from OneSpan are corrupted. We are using Java SDK. Are there previous examples of this and fixes?
Thanks.
Reply to: Corrupt PDFs
Wednesday, March 3, 2021 at 01:30pmHi Esteban,
Do those corrupted PDFs with size of 0 bytes? Or can't open and with normal size? If the former, I think you can add a retry mechanism to prevent it.
Duo
Reply to: Hi Esteban, Do those…
Wednesday, March 3, 2021 at 01:32pmCan't open with the normal size is our situation.
Reply to: Corrupt PDFs
Wednesday, March 3, 2021 at 01:42pmHi Esteban,
Have you already got a support ticket of it? Do you have an corrupted example where the PDF doesn't contain sensitive information, and also download an openable copy as a comparison?
Duo
Reply to: Corrupt PDFs
Wednesday, March 3, 2021 at 03:37pmHi Duo. I attached the two files.
I have attached the original files. If you open using Notepad++ you will see they are full of NULLS.
Reply to: Hi Duo. I attached the two…
Wednesday, March 3, 2021 at 04:10pmHi Esteban,
Thanks for the sharing! And true that seems every byte is NULL char for these two files:
File file = new File("C:\\......\\Application for Refund-TRS6ES-636499.PDF");
byte[] fileContent = Files.readAllBytes(file.toPath());
for (byte b : fileContent) {
System.out.println(b == '\u0000');
}
I believe this provides a thread of thinking about how to test against the downloaded byte array:
byte[] documentByte = eslClient.downloadDocument(new PackageId("package_id"), "documentId");
However, it's also possible that the corruption happened when processed the output stream storing the byte array to your local or a remote storage. Is it possible to share where you stored these data and the the code around how your application stores the downloaded byte array?
Duo
Reply to: Corrupt PDFs
Thursday, March 4, 2021 at 01:36pmHi Duo:
We are using java.io.FileOutputStream to write PDF file to a Windows network drive.
Does that help?
Reply to: Hi Duo: We are using java…
Thursday, March 4, 2021 at 02:54pmHi Esteban,
I have few thoughts about it:
#1. You can add a retry mechanism in your code and detect if the downloaded byte array are full of null bytes / if the first char is '%', like below:
EslClient eslClient = new EslClient(API_KEY, API_URL);
int retry = 3;
byte[] fileContent = null;
while(retry-- > 0) {
fileContent = eslClient.downloadDocument(new PackageId("dL0ACE8iwBQ7zzBQUfzgv-hLLB8="), "Document1");
if(fileContent != null && (char)fileContent[0] == '%') {
break;
}
// or
// if(fileContent != null && fileContent[0] == '\u0000') {
// continue;
// }else {
// break;
// }
//
}
#2. You can also duplicate the downloaded byte array to a local drive and see if both locations experience the same
Duo
Reply to: Corrupt PDFs
Friday, March 5, 2021 at 10:18amI'll go ahead and try the retry code with a minor modification to loop:
int retry = 0;
byte[] fileContent = null;
while(retry < 3) {
fileContent = eslClient.downloadDocument(documentPackage.getId(), document.getId().getId());
if(fileContent != null && (char)fileContent[0] == '%') {
break;
}
retry++;
}