praxedis

Corrupt PDFs

0 votes

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

0 votes

Hi 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

 

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Corrupt PDFs

0 votes

Hi 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

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Corrupt PDFs

0 votes

Hi 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:

0 votes

Hi 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

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Corrupt PDFs

0 votes

Hi Duo:

We are using java.io.FileOutputStream to write PDF file to a Windows network drive.

Does that help?


Reply to:

0 votes

Hi 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

 

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Corrupt PDFs

0 votes

I'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++;
                }


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off