Base64-Encoding

From Updox API
Revision as of 11:33, 5 December 2013 by Thenate (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Code samples for base-64 encoding a file in order to attach it to an API call...

Language Source Code Examples
Java
 File file = new File("c:\filename.ext");
 
 byte[] bytes = loadFile(file);
 
 byte[] encoded = Base64.encodeBase64(bytes);
 
 String encodedString = new String(encoded);
 
C#


 byte[] xmlDataByteArray;
 
 System.IO.FileStream inFile;
 
 inFile = new FileStream("C:\\filename.ext", FileMode.Open, FileAccess.Read);
 
 xmlDataByteArray = new byte[inFile.Length];
 
 long bytesRead = inFile.Read(xmlDataByteArray, 0, Convert.ToInt32(inFile.Length));
 
 inFile.Close();
 
 String strBase64 = Convert.ToBase64String(xmlDataByteArray, 0, xmlDataByteArray.Length);