Parsing MIME Response - Splitting base64 String into an Array 
June 16th, 2009, 03:38 PM
| | Newbie | | Join Date: Jun 2009
Posts: 4
| |
Hi Everybody,
I've been working on this challenge for a while now without much luck. What I'm attempting to do is split a MIME byte response into its individual images. I am given the boundary to split on in the HTTP header but when I attempt the following code it doesnt work. If anybody has some suggestions on what I should attempt here I would greatly appreciate it. -
'boundary to split on
-
Dim boundary as string = _
-
"boundarystring"
-
-
'read the HTTP response into byte array
-
Dim byteArray() as Byte = memoryStream.ToArray()
-
-
'convert the byte array into base64 string
-
Dim base64String as String = _
-
System.Convert.ToBase64String(byteArray, 0 byteArray.Length)
-
-
'attempt to split base64 string by base64 version
-
'of boundary to retrieve individual photos
-
Dim base64Array() as String = _
-
base64String.Split(System.Convert.ToBase64String( _
-
System.Convert.FromBase64String(boundary)))
-
-
'then convert each base64 string back to image....
-
| 
June 16th, 2009, 04:48 PM
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,690
Provided Answers: 3 | | | re: Parsing MIME Response - Splitting base64 String into an Array Quote: |
but when I attempt the following code it doesnt work.
| Can you be more detailed about what 'doesn't work' means? Exceptions... first image is good, rest are junk... none are good...
| 
June 16th, 2009, 09:09 PM
| | Newbie | | Join Date: Jun 2009
Posts: 4
| | | re: Parsing MIME Response - Splitting base64 String into an Array
Sorry I suppose that might be helpful... The problem is when I attempt to split the base64 response with the base64 version of the boundary string it doesnt create an array. Its as though it cant locate the boundary within the response.
In the past I have tried converting the byte array into a string then splitting on the boundary as is. This actually works but when I attempt to convert each string element of the array back to a byte array and save it as an image it ends up corrupt.
| 
June 16th, 2009, 11:11 PM
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,690
Provided Answers: 3 | | | re: Parsing MIME Response - Splitting base64 String into an Array Quote: |
Its as though it cant locate the boundary within the response.
| Then the next step is to confirm your theory.
Before actually doing the split do a find for the boundary. You should get an index of it's location. If you get a -1 then it didn't find it
| 
June 17th, 2009, 03:07 PM
| | Newbie | | Join Date: Jun 2009
Posts: 4
| | | re: Parsing MIME Response - Splitting base64 String into an Array
Ok unfortunately it does appear as though it can't locate the boundary; as I am receiving a response of -1.
| 
June 17th, 2009, 04:33 PM
| | Newbie | | Join Date: Jun 2009
Posts: 4
| | | re: Parsing MIME Response - Splitting base64 String into an Array
Here's an example of the boundary/response in string and base64 formats, I have only included the header portion of the response: String
Boundary:
--simple boundary
Response:
--simple boundary
Content-ID:2923871
Object-ID:1
Content-Description:
Content-Type:image/jpeg
------------------------------------------------------------------- Base64
Boundary:
c2ltcGxlIGJvdW5kYXJ5AA==
Response:
DQotLXNpbXBsZSBib3VuZGFyeQ0KQ29udGVudC1JRDoyOTIzOD cxDQpPYmplY3QtSUQ6MQ0KQ29udGVudC1EZXNjcmlwdGlvbjoN CkNvbnRlbnQtVHlwZTppbWFnZS9qcGVnDQ==
------------------------------------------------------------------
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,652 network members.
|