473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Parsing MIME Response - Splitting base64 String into an Array

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.

Expand|Select|Wrap|Line Numbers
  1. 'boundary to split on
  2. Dim boundary as string = _
  3. "boundarystring"
  4.  
  5. 'read the HTTP response into byte array
  6. Dim byteArray() as Byte = memoryStream.ToArray()
  7.  
  8. 'convert the byte array into base64 string
  9. Dim base64String as String = _
  10. System.Convert.ToBase64String(byteArray, 0 byteArray.Length)
  11.  
  12. 'attempt to split base64 string by base64 version
  13. 'of boundary to retrieve individual photos
  14. Dim base64Array() as String = _
  15. base64String.Split(System.Convert.ToBase64String( _
  16. System.Convert.FromBase64String(boundary)))
  17.  
  18. 'then convert each base64 string back to image....
  19.  
Jun 16 '09 #1
5 4213
tlhintoq
3,525 Expert 2GB
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...
Jun 16 '09 #2
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.
Jun 16 '09 #3
tlhintoq
3,525 Expert 2GB
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
Jun 16 '09 #4
Ok unfortunately it does appear as though it can't locate the boundary; as I am receiving a response of -1.
Jun 17 '09 #5
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==
------------------------------------------------------------------
Jun 17 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Magnus | last post by:
Hi, I'm programatically posting an image using multipart/form-data. It sends to the server OK, but when I try to view it in the browser, it is still in the base64 string I sent it as:...
2
by: Dmitri Shvetsov | last post by:
Hi All, Does somebody know what's the length's ratio in we convert byte to base64 string? Is it a constant ratio or it can be different from case to case? For example if I convert a byte array...
4
by: JeffM | last post by:
Quick C# question: I have comma delimited values in a string array that I want to pass to seperate variables. Any tips on splitting the array? Thanks in advance! JM
5
by: AC [MVP MCMS] | last post by:
Any pointers on how to (1) read a Base64 encoded string from a text file and (2) write it to a binary file? I have a ton of files that are being generated from a legacy system. Each file...
4
by: Kliot | last post by:
I have a string that is a base64 graphic that I need to convert to a file, can someone give me some pointers on how to do this? Thanks
7
by: Neo Geshel | last post by:
Greetings. I have managed to stitch together an awesome method of posting text along with an image to a database, in a way that allows an unlimited number of previews to ensure that text and...
5
by: Rasmus | last post by:
In a asp.net site i need to make a url link like this:...
2
by: CharChabil | last post by:
Using Vb.net 2005, I want to read each part in this string in an array (splitting the string) ----------- A1/EXT "BK82 LB73 21233" 105 061018 1804 ----------- That Code that i used is as follow:...
3
by: Morten71 | last post by:
I have a strange problem. I have a local string() var I populate this way: clmns() As String = {"InvoiceNo", "InvoiceDate"} When I call: Array.IndexOf(clmns,"InvoiceDate") I get 0 (zero) as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.