I'm trying to decode a base64 pdf file and send it to another endpoint.
I used a python policy for the decoding part and here's the code
```
import base64
pdfB64 = flow.getVariable("request.content")
pdfFile = base64.b64decode(pdfB64)
flow.setVariable("pdfFileDecoded",pdfFile)
```
Now, when I send my http post request which is below
```
headers :
Accept : */*
boundary : --Boundaryy
--Boundaryy
Content-Disposition: form-data; name="testdu12janvier"; filename="testdu12janvier.pdf"
Content-Type: application/pdf
<< Heres is sensitive data which is basically a base64 encoded pdf file >>
--Boundaryy--
```
When I send this POST request and trace it in Apigee Edge, I notice that something else is encoded before the pdf file I think its either the boundary or one of the headers. This makes a corrupt pdf file which can't be read.
How do I isolate the pdf file from the request body without removing boundaries? as I'll need to send multiple in near future.
Solved! Go to Solution.
I'm trying to decode a base64 pdf file and send it to another endpoint.
I used a python policy for the decoding part and here's the code
ok that's clear, sounds good. But... base64.b64decode() returns a bytes object. Not a String. Storing that bytes object into a flow variable will probably not ... work properly.
Now, when I send my http post request which is below
How did you construct that multi-part message? Did you use AssignMessage? AssignMessage will most likely treat everything you assign into the payload as a string. As I said above, the decoded PDF is not a string, it's a python bytes object. AssignMessage will probably try to coerce it to a string, but that won't do what you want.
How do I isolate the pdf file from the request body without removing boundaries? as I'll need to send multiple in near future.
There is a Java callout that can help produce or parse multi-part form messages . You might want to try using that. It will work in Apigee Edge, but I think it won't work in Apigee X.