我想对图像进行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);