email - Http Response Contains MIME stream.. which has binary Images seperated by Boundary String.. need to get those Images and save using c# -
when make http request server responses mime response stream has 2 or more images in binary data separated boundary string need extract images , save them individually database
stream looks this...
header has
rets-version: rets/1.0 mime-version: 1.0 content-type: multipart/parallel; boundary="simple boundary"
http resoinsestream has
--simple boundary
content-type: image/jpeg content-id: 123456 object-id: 1 <binary data>(image1)
--simple boundary
content-type: image/jpeg content-id: 123457 object-id: 1 <binary data>(image2)
--simple boundary --
i need extract image1 , image2 , save in database binary image.
if use mimekit library, can easily:
static mimeentity parsehttpwebresponse (httpwebresponse response) { var contenttype = contenttype.parse (response.contenttype); return mimeentity.parse (contenttype, response.getresponsestream ()); } static void saveallimages (httpwebresponse response) { var entity = parsehttpwebresponse (response); var multipart = entity multipart; if (multipart != null) { foreach (var image in multipart.oftype<mimepart> ()) { using (var memory = new memorystream ()) { image.contentobject.decodeto (memory); var blob = memory.toarray (); // save database } } } }
Comments
Post a Comment