我想对图像进行base64编码,然后将其作为HttpPostedFileBase接收,以将其发送到json对象中,但我不知道该怎么做...请告诉我如何将其解码回HttpPostedFileBase

最佳答案

我尝试了这个并且有效

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);

07-26 07:18