Converting a File to a Base64 Encoded String
May 8th, 2008
Sometimes it is necessary to send a file to someplace, but not practical to send it as a binary file. This is where base64 encoding comes in handy. Such a think has many uses, for example in webservices. It may be necessary to send a file via webservice to some 3rd party system. Base64 encoding allows you to overcome the firewall by converting that binary data to string data. Here’s an example of converting a file to Base64 encoding.
-
private string ConvertFileToBase64(string Filename)
-
{
-
string result = "";
-
-
{
-
reader.Read(buffer, 0, (int) reader.Length);
-
-
result = Convert.ToBase64String(buffer);
-
}
-
-
return result;
-
}
And there you have it! Send that puppy all over the internet!
May 8th, 2008 at 3:14 pm
[...] out my new article on encoding files as base64 strings. Useful for sending binary data across the wire where sending such binary data [...]