473,396 Members | 1,846 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,396 software developers and data experts.

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 4807
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 thread has been closed and replies have been disabled. Please start a new discussion.

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:...
1
by: Mr.Clean | last post by:
I need to write a function to return an image that has been base64 encoded into a string. This is how it is done in PHP and I need to know how I can do the same in javascript: function...
5
by: mike | last post by:
Is there any way I can change the content type when I open a new window other than opening a script in the open statement? mywin =...
3
by: Guoqi Zheng | last post by:
Dear sir, I need to decode base64 encoded email. I used below function but it does not work correctly, especially when I need to decode some Characters like Chinese, Can some one point out...
0
by: xavier_bizoux | last post by:
Hi, I'm new to javascript and to AJAX and I get a strange behaviour. I wrote a code which works perfectly in IE but not in Firefox. Could you please have a look to the following site with FF and...
5
by: Rasmus | last post by:
In a asp.net site i need to make a url link like this:...
5
by: Rasmus | last post by:
In a asp.net site i need to make a url link like this:...
2
by: John | last post by:
i have the following code to open a URL address, but can you please tell me how can I check the content type of the url response? Thank you. try: req = Request(url, txdata, txheaders) handle...
5
by: smclellan86 | last post by:
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.