Multi-part form parsing code for REST api responses and mime data

More
8 months 4 days ago - 8 months 1 day ago #473 by mike S
mike S created the code: Multi-part form parsing code for REST api responses and mime data
handles parsing multi-part forms from response body in a REST api into the different parts including each part's headers and body.
Original version by Daryl Foster.
Contains 2 nvo objects: the multi-part form parser and the objects that get created for each part.
Utilizes content-length if available in the header.

The actual encoding used should be in the header of the main rest response. That would need to be set as needed prior to parsing the object. Assumes UTF-8 if not set.

sample usage:
...
inv_http.GetResponseBody(lblb_blob)
ls_content_type = inv_http.getresponseheader( 'Content-Type' )

ls_boundary = lnv_multi_part_extraction.of_GetBoundary(ls_content_type)
ll_parts = lnv_multi_part_extraction.of_Parse(lblb_blob, ls_boundary) // n_cst_multipart by Daryl Foster

// Get part 1 - assumes json here
ls_content_type = lnv_multi_part_extraction.io_parts[1].of_GetHeader('Content-Type')
ls_Content_Length = lnv_multi_part_extraction.io_parts[1].of_GetHeader( 'Content-Length' )
ls_ReturnJson = string(lnv_multi_part_extraction.io_parts[1].iblb_data, iencoding_ ) //if it is json

// Get part 2
ls_content_type = lnv_multi_part_extraction.io_parts[2].of_GetHeader('Content-Type')
ls_content_disposition = lnv_multi_part_extraction.io_parts[2].of_GetHeader('Content-Disposition')
ls_Content_Length = lnv_multi_part_extraction.io_parts[2].of_GetHeader("Content-Length")
ablob_image = lnv_multi_part_extraction.io_parts[2].iblb_data //if it is an image


more info:
community.appeon.com/index.php/qna/q-a/h...tipart-response-body
stackoverflow.com/questions/4238809/exam...-multipart-form-data

This message has an attachment file.
Please log in or register to see it.

Last Edit: 8 months 1 day ago by Bruce Armstrong. Reason: trying again and again to DELETE n_cst_multipart_part.zip

Please Log in or Create an account to join the conversation.

More
7 months 3 weeks ago #476 by Daryl Foster
Daryl Foster replied the code: Multi-part form parsing code for REST api responses and mime data
Thanks Mike, this code should also work with any multipart MIME messages, not just REST. The other obvious one that people may need it for is XOP from SOAP (Content-Type: application/xop+xml;)

Please Log in or Create an account to join the conversation.

Moderators: Appeon Administrator