Parsing multipart content stream


I am using a DSP to post the form to a flow service. In the form I am doing a file upload (.zip file) and some entries in the text fields. The enc-type is ‘multipart/form-data’.

When the multipart content handlers are loaded properly there is no problem in peocessing the submitted form as the content handler will parse each part and make it available for processing.

But when the IS is restarted, the multipart content handlers are not being loaded few times. In such cases when the form is submitted the form data is coming into the flow as ‘contentStream’. So the implementation fails until the multipart content handlers are reloaded.

So I would like to change my implementation slightly. When the content handlers are loaded then no problem. Otherwise I would like to parse the content stream into individual parts.

Can someone help me in doing this?


I found the solution myself. May be its useful to some of you in future. I did parse the multipart stream using the built-in mime services. But you have to do some string operations to get uploaded filename, size.

  1. Use getTransportInfo to get the transport information.
  2. Have a condition if uploadedFile document is null(The document for html element in the uploading form). If its null then it means the multipart is not parsed.
  3. pub.mime:mergeHeaderAndBody (use reuestHdrs of transportInfo and contentStream. Output is a stream).
  4. createMimeData (Use the stream thats created).
  5. getNumParts (To know the no.of parts in the mime).
  6. Now for each part number (not a loop) use getBodyPartContent (pass part number, index starts from zero).
  7. Convert the stream to string. This is for not-file type parts of the form.
  8. For uploaded file use getBodyPartHeader and parse. Convert it into a string and parse for filename and size (Some string manipulations).
  9. Get the uploaded file content using getBodyPartContent and save the stream to a file using the name you got in step-8.

The limitation here is you have to know the part number for the file type elements. The order will be same as the order you give in the uploading html form.


1 Like

in step 3 - you mention use requestheaders of transportinfo - transport=headerlines doesn’t seem to like it and I get a
2009-02-03 17:07:33 PST [ISP.0068.0013W] Error processing service: [ISS.0068.9006] Server Error: [ISS.0086.9157] Not able to convert headerLines to byte array

Could you elaborate - this posting looks quite useful to what i am trying to do

I don’t know about the error you got. I am uploading the package with the implementation and a sample html form to post MIME to the service. This may help you. (Just change the IS address and port).

<h2>This HTML uploads a MIME to WM6.5 service. <br/>The parsed parts will be displayed on the screen</h3>
<FORM name="upload" method="post" accept=".zip"  enctype="multipart/form-data" action="[URL]http://server:port/invoke/rbwmmimeupload:parseMIMEUpload[/URL]">
 Email Address: &nbsp;<INPUT type="text" name="emailAddress" /><br/><br/>
 File: &nbsp;<INPUT type="file" name="uploadFile" size="40"/><br/><br/>
 Supplier Code: &nbsp;<INPUT type="text" name="suppcode"/><br/><br/>
 <INPUT type="submit" value="Upload File"/> 

Guna (14.7 KB)

Right - i see what your doing - and I am trying to operate off email(is service(from :5555 Security/Ports/Email) monitoring an notes email box and picking up the email and sending it to service) being the source of the input instead of a web page upload as you have - but I would probably use something like this in the future.

So i am running into the MergeHeaderAndBody wants a header(headerLines) input but the doesn’t have anything such as the transport.http.reqeuesthdrs to pass into headerLines - what should be used instead?

I used your service and it process fine w/o attachments but I attached a txt or doc file and it failes to execute service and the log only says:
2009-02-04 10:31:57 PST [ISP.0068.0026D] Content type: multipart/mixed; boundary="=mixed 0065c8d288257553=" Subject: bpm.mailToIS:receiveEmail

but the receiveEmail service doesn’t look like it is kicked off - without attachments it executes;
2009-02-04 10:24:35 PST [ISP.0068.0026D] Content type: multipart/alternative;
boundary="=alternative 00651c3088257553=" Subject: bpm.mailToIS:receiveEmail

and the only thing I notice is it comes across as multipart/aleternative oppose to with attachements as multipart/mixed which doesn’t process?

Hey I got it. In this case you need not merge header and body. You just make sure if you have the below settings for the email port configuration on IS admin console.

  1. Invoke service for each part of multipart message - NO
  2. Include email headers when passing message to content handler - YES.

Now in the service, you invoke the service createMimeData and just pass the contentStream as input. Now get the no.of parts. This will be no.of attachements+1. Leave the 0th part (its not the attachment. I don’t know what it is). Get the parts from 1 which are your attachments and save the stream. For each part/Headers/Content-Type contains the attached file name also. You have do some str ops to get it.

I just made this service and am successfully reading the attachements from Outlook.


When I select " Invoke service for each part of multipart message - NO" then it doesn’t process any of the message so I don’t know the importance of having this set to No - I don’t see anything in the logs as to why it doesn’t even try to process the message when set to NO so i have to keep it at yes - does that cause problems?

Yes, it should be set to NO. Other wise what you get in the service is a part of the message each time you send a mail rather than all the parts at a time as a multipart. In such case you can try the same approach above and get the content-type in the header (after getting the mime from content stream) for each part. If this contains a filename in it then you can process that part ortherwise skip the part.


Why did you mention not a loop in step 6. Can’t we process each body part in a loop?

May be you can.
In my case, I needed to process each part differently so the order matters to me.


Could you please send me the code how u are reading the eamil attachment.


Hi did any one parsed bodyPart Content type: multipart/alternative ?if yes please let me know the process

Thanks in Advance