@Dino
First off thankyou so much for helping us and the community.
Continuation to below post we need to send the message as multi part request.
https://community.apigee.com/questions/56914/decode-base64-image-in-apigee.html
We did decode the image, construct the multi part using JS & assign as below but somehow backend api is not really happy with the request. Wondering if below is good or something needs to be corrected?
Backend api expects as - Image * file (formData)
Tested using POSTMAN using form-data attachment simply works but while doing below sequence is causing issues.
Not sure how to be sure on content-length?
In general can you check and see what could be potential issues?
==
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <JavaCallout async="false" continueOnError="false" enabled="true" name="Java-Callout-1"> <DisplayName>Java Callout-1</DisplayName> <Properties> <Property name="action">decode</Property> <Property name="mime-type">image/jpeg</Property> </Properties> <ClassName>com.google.apigee.edgecallouts.Base64</ClassName> <ResourceURL>java://edge-custom-base64-1.0.3.jar</ResourceURL> </JavaCallout>
==
var boundary = Math.random().toString().substr(2); var multipart =""; multipart = "----------------------------" + boundary+"\r\n" + "Content-Disposition: form-data; name=\"image\"; filename=\"front_image.jpeg\"" +"\r\n" + "Content-Type: image/jpeg" + "\r\n\r\n" + request.content + "\r\n" + "----------------------------" + boundary+"\r\n"; var n = multipart.length; context.setVariable("multipart", multipart); context.setVariable("boundary", boundary); context.setVariable("multipartLength", n);
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-3"> <DisplayName>Assign Message-3</DisplayName> <Properties/> <Add> <Headers> <Header name="Content-Type">multipart/form-data;boundary=----------------------------{boundary}</Header> </Headers> </Add> <Payload variablePrefix="@" variableSuffix="#"> @multipart# </Payload> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>
Solved! Go to Solution.
Not sure exactly, but here's what I think
This part
multipart/form-data;boundary=----------------------------{boundary}
seems hard to debug. The basic format requires "double dash" followed by the boundary string. If you include dashes in the boundary string it makes it difficult to verify that the boundary is being formatted correctly with the required double-dash prefix. We are left with counting tiny little dashes and trying to remember, should it be 24? or 26? If you confine the boundary string to just alphanumeric, then it's easier to see. I think you want
multipart/form-data;boundary={boundary}
and then you'd need to also modify the JavaScript to be like this:
var boundary = Math.random().toString().substr(2); var multipart = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"image\"; filename=\"front_image.jpeg\"" + "\r\n" + "Content-Type: image/jpeg" + "\r\n\r\n" + request.content + "\r\n" + "--" + boundary + "--\r\n";
Note: the ending boundary needs to have a final trailing "--" prior to the CR/LF
For the AssignMessage / Payload, I would use something like this:
<Payload>{multipart}</Payload>
You should be able to ignore content-length and just let Apigee auto-compute it.
It seems like it is a "mutlipart" form with just a single part. Is that right?
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |