Sending decoded pdf file returns blank page

The task here was to decode a pdf file and send it as a form-data.

The backend receives the decoded pdf file and everything on apigee end seemed to work fine.

When we go to check the received pdf file, it's blank, but it's not empty as the size is not a little over 300 Kb.

I used a python policy to decode and a java callout to create the form-data as it is the expected format on the backend.

here is the python code used in the policy :

 

 

import base64

pdfB64 = flow.getVariable("File")

pdfFile = base64.standard_b64decode(pdfB64)
flow.setVariable("pdfFileDecoded",pdfFile)

 

 

and here is the java policy :

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JavaCallout name="Java-CreateMultipartForm">
<Properties>
<Property name="contentVar">pdfFileDecoded</Property>
<Property name="contentType">application/pdf</Property>
<Property name="want-base64-decode">false</Property>
<Property name="part-name">{Name}</Property>
<Property name="fileName">{fileName}</Property>
</Properties>
<ClassName>com.google.apigee.callouts.MultipartFormCreator</ClassName>
<ResourceURL>java://apigee-multipart-form-20210401.jar</ResourceURL>
</JavaCallout>

 

 

The Java code used in this Java Callout comes from this repo :  

https://github.com/DinoChiesa/Apigee-Java-Simple-MultipartForm 

I even tested the decoding in a python script and made it write to a file and the file was correctly parsed.

Any idea why it sends a blank pdf instead of a readable file ? 

Solved Solved
0 3 1,343
1 ACCEPTED SOLUTION

ps I have created a newer v2 of the multipart/form-data callout; this one has fewer dependencies.  I had some trouble getting the original one to work in Apigee X and suspected it was because one of the dependencies was causing a problem. This may or may not be true.  But anyway with the original callout there were two external dependencies, which then brought in dependencies on the Servlet API, Guava, and some other things. I thought that was less than optimal, for just a stream parsing / consolidation tool.  

So I re-implemented my own parsing and creation of multipart/form-data payloads, with no external dependencies.  It works in Apigee X. If you were using the other one, you might want to explore this one.

https://github.com/DinoChiesa/Apigee-Java-MultipartForm-V2

 

View solution in original post

3 REPLIES 3

Not sure! 

Maybe try sending it to a different endpoint that accepts multipart/form-data requests. Something with more diagnostic information.

One possibility is that the "encoded file" (the thing you retrieve with Flow.getVariable("File")) is not encoded properly. Is it base64?  base64url?  Maybe verify the checksum of the decoded data, that it matches the checksum of the original PDF. 

Hello  @dchiesa1 ,

First off thank you for your reply and your time.

I have checked the pdf file ( which is base64 ) using python compiler (even tried comparing all functions that decode base64 and it was the same ) and it renders a proper file. But when the same file goes through Apigee, it's blanc.

I will try however to make an API that returns more data and send to it, that's a great idea to check for what's going on and I'll update in case there's something. Thank you.

ps I have created a newer v2 of the multipart/form-data callout; this one has fewer dependencies.  I had some trouble getting the original one to work in Apigee X and suspected it was because one of the dependencies was causing a problem. This may or may not be true.  But anyway with the original callout there were two external dependencies, which then brought in dependencies on the Servlet API, Guava, and some other things. I thought that was less than optimal, for just a stream parsing / consolidation tool.  

So I re-implemented my own parsing and creation of multipart/form-data payloads, with no external dependencies.  It works in Apigee X. If you were using the other one, you might want to explore this one.

https://github.com/DinoChiesa/Apigee-Java-MultipartForm-V2