So here is my dilemma. I need to handle POST requests coming from a customer server. The request body is of a "multipart/mixed" type. I am having to use standard ASP.NET so I'm having to brute force what Core makes alot easier I know. I have it mostly working, but having an issue with a PDF attachment coming through as one of the parts. Here's the basic algorithm of my approach.
- Request header comes across defining the multipart boundary in the content type header, so I'm grabbing the boundary out of that header
- Grabbing the stream body as a UTF8 string
- Splitting it with the boundary as the delimiter
- Resulting split is 2 parts, one is xml defining a purchase order from customer, I can parse and handle that xml just fine, generate my object model from it, etc. no issue
Second part is a PDF file attachment of type "application/pdf". It is at this point I am having problems getting this into a legible PDF file, it always comes up as a 2 page blank document. What I'm doing currently is using my object model to generate an HTML formatted email containing the order info from the XML, and then attach the included PDF onto the email as an attachment. Here is how I'm handling this now
A. Using UTF8 encoding to convert string back into byte[]
B. Writing byte[] into a memory stream
C. Adding attachment to MailMessage using memory stream
So this results in an email coming over, with an adequately sized attachment, but the attachment is blank, it opens up in reader as a 2 page blank document. What I find interesting is not that its blank, but that it's 2 pages (Contact movie reference for humor).
Can anyone shed any light onto what I may be doing wrong? I've tried a few alternate things, such as using ASCII encoding to write a string into the memory stream instead of the byte[] but that didnt seem to work either. Also, just for kicks I set up a trial azure website using Core, and grabbing the content stream using their MultiPartContent object model, and that stream still just results in a blank document, so I don't think my overall approach is wrong, just maybe I'm missing something in the encoding loop?
Thanks in advance for any help anyone may be able to give!