base64 encode HttpPostedFileBase

Abdallah

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

Abdallah

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.

edited at
0

Comments

0 comments
Login to comment

Related