469,950 Members | 2,305 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Read Base64 string to write a .gif (or other content type)

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 contains a (1) content type one one line, a (2) filename, and (3) the
encoding type (seems to always be Base64, followed by the encoded string.
A process will be to read the content type and filename, then create a new
binary file and write out the converted base64 string.

Ideas?

--
-AC [MVP MCMS]
http://www.andrewconnell.com
http://www.andrewconnell.com/mvp
Nov 18 '05 #1
5 4522
How 'bout System.Convert.FromBase64String ()

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"AC [MVP MCMS]" <sw*********@gmail.com> wrote in message
news:9c**************************@msnews.microsoft .com...
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 contains a (1) content type one one line, a (2) filename, and (3) the
encoding type (seems to always be Base64, followed by the encoded string.
A process will be to read the content type and filename, then create a new
binary file and write out the converted base64 string.

Ideas?

--
-AC [MVP MCMS]
http://www.andrewconnell.com
http://www.andrewconnell.com/mvp

Nov 18 '05 #2
Hello James,

Thanks... I guess I should have been more specific. I have that part, converting
the string to a byte array. But for images, I've noticed that there's a
header at the start of the file (appears to be just plain text, but not sure)...
for example a gif has GIF[version] at the start of the file.

I've tried writing out "GIF89a" at the start and then the byte array, but
that didn't work. Then I tried writing the GIF89a to a separate byte array,
write that out and then write the data stream byte array... but that didn't
work. I've seen some examples in this NNTP about using the BinaryWriter,
and comments by Jon Skeet how that's not necessary, but having a hard time
finding a single example of how to write this out on your own.

I'm not only interested in writing out GIF's, but also BMPs, JPEG, PNGs,
ZIPs, DOCs, XLSs, etc...

Ideas?

--
-AC [MVP MCMS]
http://www.andrewconnell.com
http://www.andrewconnell.com/mvp
How 'bout System.Convert.FromBase64String ()

Home: www.noveltheory.com Work: www.njtheater.com Blog:
www.honestillusion.com Day Job: www.partsearch.com "AC [MVP MCMS]"
<sw*********@gmail.com> wrote in message
news:9c**************************@msnews.microsoft .com...
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 contains a (1) content type one one line, a (2) filename,
and (3) the encoding type (seems to always be Base64, followed by the
encoded string. A process will be to read the content type and
filename, then create a new binary file and write out the converted
base64 string.

Ideas?

--
-AC [MVP MCMS]
http://www.andrewconnell.com
http://www.andrewconnell.com/mvp

Nov 19 '05 #3
Create a MemoryStream from the byte[]. Use the FromStream() and Save()
methods of System.Drawing.Image.

AC [MVP MCMS] wrote:
Hello James,

Thanks... I guess I should have been more specific. I have that
part, converting the string to a byte array. But for images, I've
noticed that there's a header at the start of the file (appears to be just
plain text, but
not sure)... for example a gif has GIF[version] at the start of the
file.
I've tried writing out "GIF89a" at the start and then the byte array,
but that didn't work. Then I tried writing the GIF89a to a separate byte
array, write that out and then write the data stream byte array...
but that didn't work. I've seen some examples in this NNTP about
using the BinaryWriter, and comments by Jon Skeet how that's not
necessary, but having a hard
time finding a single example of how to write this out on your own.

I'm not only interested in writing out GIF's, but also BMPs, JPEG,
PNGs, ZIPs, DOCs, XLSs, etc...

Ideas?

How 'bout System.Convert.FromBase64String ()

Home: www.noveltheory.com Work: www.njtheater.com Blog:
www.honestillusion.com Day Job: www.partsearch.com "AC [MVP MCMS]"
<sw*********@gmail.com> wrote in message
news:9c**************************@msnews.microsoft .com...
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 contains a (1) content type one one line, a (2) filename,
and (3) the encoding type (seems to always be Base64, followed by
the encoded string. A process will be to read the content type and
filename, then create a new binary file and write out the converted
base64 string.

Ideas?

--
-AC [MVP MCMS]
http://www.andrewconnell.com
http://www.andrewconnell.com/mvp


--
Truth,
James Curran [erstwhile-MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Nov 20 '05 #4
Hello James,

This will work for images... but will it work for other content types (ZIP,
DOC, XLS)?

--
-AC [MVP MCMS]
http://www.andrewconnell.com
http://www.andrewconnell.com/mvp
Create a MemoryStream from the byte[]. Use the FromStream() and
Save() methods of System.Drawing.Image.

AC [MVP MCMS] wrote:
Hello James,

Thanks... I guess I should have been more specific. I have that
part, converting the string to a byte array. But for images, I've
noticed that there's a header at the start of the file (appears to be
just
plain text, but
not sure)... for example a gif has GIF[version] at the start of the
file.
I've tried writing out "GIF89a" at the start and then the byte array,
but that didn't work. Then I tried writing the GIF89a to a separate
byte
array, write that out and then write the data stream byte array...
but that didn't work. I've seen some examples in this NNTP about
using the BinaryWriter, and comments by Jon Skeet how that's not
necessary, but having a hard
time finding a single example of how to write this out on your own.
I'm not only interested in writing out GIF's, but also BMPs, JPEG,
PNGs, ZIPs, DOCs, XLSs, etc...

Ideas?
How 'bout System.Convert.FromBase64String ()

Home: www.noveltheory.com Work: www.njtheater.com Blog:
www.honestillusion.com Day Job: www.partsearch.com "AC [MVP MCMS]"
<sw*********@gmail.com> wrote in message
news:9c**************************@msnews.microsoft .com...

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 contains a (1) content type one one line, a (2)
filename, and (3) the encoding type (seems to always be Base64,
followed by the encoded string. A process will be to read the
content type and filename, then create a new binary file and write
out the converted base64 string.

Ideas?

--
-AC [MVP MCMS]
http://www.andrewconnell.com
http://www.andrewconnell.com/mvp

Nov 20 '05 #5
AC [MVP MCMS] wrote:
This will work for images... but will it work for other content types
(ZIP, DOC, XLS)?


What exactly are you starting with? If the Base64 is a binary image of
the file you want write, why are you bothering with conversions at all.
Just write out the bits, and give it the appropriate extension.

--
Truth,
James Curran [erstwhile-MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mr.Clean | last post: by
5 posts views Thread by mike | last post: by
3 posts views Thread by Guoqi Zheng | last post: by
5 posts views Thread by Rasmus | last post: by
5 posts views Thread by Rasmus | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.