I want to base64
encode an image that is being received as HttpPostedFileBase
to send it in a json object and I don't know how it can be done...and please tell me how can I decode it back to HttpPostedFileBase
I tried this and it worked
string theFileName = Path.GetFileName(YourFile.FileName);
byte[] thePictureAsBytes = new byte[YourFile.ContentLength];
using (BinaryReader theReader = new BinaryReader(YourFile.InputStream))
{
thePictureAsBytes = theReader.ReadBytes(YourFile.ContentLength);
}
string thePictureDataAsString = Convert.ToBase64String(thePictureAsBytes);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments