[Multipart/form-data] Errors on parsing binary data with MultiPartFormDataParse
Question
Forge component by Kilian Hekhuis
Application Type
Service
Service Studio Version
11.10.13 (Build 39571)
Platform Version
11.10.1 (Build 23852)

When using the MultiPartFormDataParse to parse binary data (mostly .jpg/.jpeg and .pdf files) I get either one of the 2 errors listed below.

Error A:

"Unexpected end of stream. Is there an end boundary? -    at HttpMultipartParser.StreamingMultipartFormDataParser.ParseParameterPart(Dictionary`2 parameters, RebufferableBinaryReader reader)
   at HttpMultipartParser.StreamingMultipartFormDataParser.ParseSection(RebufferableBinaryReader reader)
   at HttpMultipartParser.StreamingMultipartFormDataParser.Parse(RebufferableBinaryReader reader)
   at HttpMultipartParser.MultipartFormDataParser..ctor(Stream stream, String boundary, Encoding encoding, Int32 binaryBufferSize)
   at OutSystems.NssMultipartFormDataParser.CssMultipartFormDataParser.MssParse_MultiPartFormData(Byte[] ssMultiPartBinary, String ssBoundary, String ssFileEncoding, RLPartContentRecordList& ssPartContentList, Boolean& ssSuccess, String& ssErrorMessage)"

Error B:

"Duplicate field in section - at HttpMultipartParser.StreamingMultipartFormDataParser.ParseSection(RebufferableBinaryReader reader) at HttpMultipartParser.StreamingMultipartFormDataParser.Parse(RebufferableBinaryReader reader) at HttpMultipartParser.MultipartFormDataParser..ctor(Stream stream, String boundary, Encoding encoding, Int32 binaryBufferSize) at OutSystems.NssMultipartFormDataParser.CssMultipartFormDataParser.MssParse_MultiPartFormData(Byte[] ssMultiPartBinary, String ssBoundary, String ssFileEncoding, RLPartContentRecordList& ssPartContentList, Boolean& ssSuccess, String& ssErrorMessage)"

Code snippet and explanation:
We retrieve a list, which contains records with binary data, from our database with an aggregate.
Then iterate over this list and check if the binary data is empty or not.
When the binary data is not empty, we will try to parse the data. The input that is used for the MultiPartFormDataParse is the records' binary data for the 'MultiPartBinary' input parameter, while the other 2 input parameters ('Boundary' and 'Encoding') are left empty.
After this the file is added to a partslist in the next steps.


To verify that the binary files we store in the database are valid, we created a simple page with a download button. This button uses the standard outsystems download widget. But we encounter no errors, every file is downloaded and opened without any problems.

What are we doing wrong with the parse action? Let me know if you need any additional explanation or information.

mvp_badge
MVP

Hi Kim,

I'm afraid you do not quite understand what the MultiPartFormDataParse action is for. It is to be used exclusively for REST services or e-mail parsers that receive multipart/form-data binary content. It is in no way suited for "parsing" data from a database (whatever that would mean).

Can you explain what kind of "parsing" of binary data from a database you were expecting to do?

Hi Killian, thank you for your reply.

I think I didn't explain myself clearly, we do use this for a rest service which needs a multipartform. The snippet I provided in my original post is only the part where we encounter the problem.

Here is the flow that is used in our code:
- The data we need to send is collected from our database. This is a text part and 1 or more binaries.
- The text is converted to JSON and used in the 'AddData' action.

- We then iterate over the binary data that need to be added.


- The text part and the binary part are all added to the list 'PartsListAttachments', that list of parts is used in the MultiPartFormDataCreate

- We noticed that the MessageBinary that is created contained some unwanted characters so we remove them in these 2 steps

- After that we use the 'ContactData' (the MessageBinary we edited in the previous step) and the contenttype as input to the rest service 'PostContactForm'




I did not include this entire flow before because the problem we encounter is at the beginning of our flow, in the action 'MultiPartFormDataParse'. We feed this action the binary data, and leave the other input fields 'Boundary' and 'Encoding' empty.
Then the action 'MultiPartFormDataParse' fails and returns the errors I described in my original post.
I hope this provides some clarification.

mvp_badge
MVP

Hi Kim,

"MultiPartFormDataParse" is only to be used for consuming REST services that send a multipart/form-data reply. For sending a request with a multipart/form-data body, you need "MultipartFormDataCreate" only. Please refer to my article here.

Also, there should never be "unwanted characters" that need replacing. If you do that, you could (and very likely will) completely corrupt any binary (or base64) you add. But again, refer to my article I linked above, I hope it'll explain how to go about this.

Hi Kilian,

Thanks for the answer and indeed that specific part has been fixed. (and the replace has been removed)
Now, for some reason when the file parts are being send to the API, they get the file, but they can't open it, like it's getting corrupted during the send.

(binarydatatotext action has been deleted and we send the binary output from the createmultipart action)

Before sending it, the file can be opened without any issue, it seems like there is something wrong when creating the formData or are we missing something?

Greetings,
Niels Favreau

Hi Niels,

Can you share how are you building the FormData payload?

Regards,

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.