71
Views
16
Comments
[Multipart/form-data] need to pass binary file to multipart/ form-data REST
Question
Forge component by Kilian Hekhuis
7
Published on 06 Sep 2019

I need to pass a binary file with certain parameters to a multipart/form-data REST service.
I am using Multipart/form-data component for the same. I am confused for the flow, I went through the demo too.
Can someone help me with steps to send the below data in body.

"account":"10101",
"contract":"101010",
"contractType":"test"
"userName":"abc@xyz.com"
*** binary file attached


Thanks,
Anagha

mvp_badge
MVP
Rank: #2

Hi Anagha,

In what format are the other parameters supposed to be delivered? JSON? Formdata?

mvp_badge
MVP
Rank: #2

Hi Anagha,

Where are you getting that error? That is, which Action gives that error? Or is the error returned from the REST service you are calling?

Rank: #3573

Hi Kilian,

In service center I am seeing this getting from ActionRequestBoundaryGet which i have used earlier but now have removed from the code. I am not getting this error now, it was probably some caching issue.
Now I am getting Unable to parse incoming data response from the service code 400.

mvp_badge
MVP
Rank: #2

I think the easiest way to troubleshoot this is if you can supply the module so I can take a look at it.

Rank: #3573

Hello Kilian,
Please find the attached sample oml. Can you please take a look and help me. Its giving 400 after the service
Need to pass the file as binary as said above.

Thanks,
Anagha

MultipartFormdataExample.oml

mvp_badge
MVP
Rank: #2

Hi Anagha,

At a first glance everything looks ok. However, I cannot know if the actual format is correct for the REST API you are calling. For example, the REST API might need a single part with all parameters, URL-encoded or JSON, instead of each being a different part. But that's something I cannot know.

Error 400 is "bad request", which means the REST API doesn't understand what you're sending. If you increase the log level of the Integration, you should be able to get more details, the REST API is likely returning some more information than just the 400 error.

Rank: #3573

Hello Kilian,

I am getting the below output from the module from the action MultipartFormDataCreate.MessageBinary by converting binary to base 64 and then base 64 to text .
But service is still returning bad request.

The file that is passed in postman request is a physical pdf file and the file that i am passing in the module is binary file. Will that make difference?


--------254eb9af-07af-470a-8430-6aca3e054f95

Content-Disposition: form-data; name="account"


79228

--------254eb9af-07af-470a-8430-6aca3e054f95

Content-Disposition: form-data; name="contract"


504363

--------254eb9af-07af-470a-8430-6aca3e054f95

Content-Disposition: form-data; name="ContractType"


Priced Contract

--------254eb9af-07af-470a-8430-6aca3e054f95

Content-Disposition: form-data; name="userName"


email@gmail.com

--------254eb9af-07af-470a-8430-6aca3e054f95

Content-Disposition: form-data; name="samplefile"; filename="simple.pdf"

Content-Type: application/pdf


<PDF>

--------254eb9af-07af-470a-8430-6aca3e054f95--



mvp_badge
MVP
Rank: #2

Hi Anagha,

I still see "ContractType" with a capital "C", while Postman has it with a lowercase "c" like all other fields. Are you sure this isn't the problem? Please retry with "contractType" instead.

Rank: #3573

Hi Kilian,

No thats not the problem.

mvp_badge
MVP
Rank: #2

Ok, thanks for checking. Another question: did you ever increase the log level, to check what the output of the REST call exactly is? I would expect the "message" to detail what it finds wrong.

mvp_badge
MVP
Rank: #2

Hi Anagha,

Where did you get the trace from? Is that the Integration trace from Service Center? Because it contains the request as Base64 instead of binary data (for example, a trace from a REST service we're using that also uses multipart/form-data looks like this:

POST https://my.host.nl/api/packages HTTP/1.1
User-Agent: OutSystemsPlatform
Content-Type: multipart/form-data; boundary="------9c2c9938-9667-4abe-9c98-ea7cee7359ea"
Accept: application/json; esl-api-version=11.18
Authorization: XXXXXXXX
Host: my.host.nl
Content-Length: 118528

<BINARY DATA>

HTTP/1.1 200 OK
Vary: Accept-Encoding
Transfer-Encoding: chunked 

)

mvp_badge
MVP
Rank: #2

Ok, so we can rule that out as well as cause of this error. I must admit I'm almost out of ideas. The example OML looks good, what we can see of the data looks good too (when I decoded the Base64, it looked good as well). One last thing to check the content of the Binary Data, is to create a testing Screen, that does all the same PartAdds and MultipartFormDataCreate, and download the output of MultipartFormDataCreate, and attach that file here, to see if I can find anything out of the ordinary.