- We have to just provide input stream as "FileUpload1.PostedFile.InputStream" to below function
Image Stream to Byte :-
public static byte[] StreamToByte(Stream input)
{
byte[] buffer = new byte[input.Length];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
Image Stream to Base64String :-
public static string StreamToBase64(Stream input)
{
byte[] buffer = new byte[input.Length];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
string temp_inBase64 = Convert.ToBase64String(ms.ToArray());
return temp_inBase64;
}
}