1, base64 format is:
data:image/jpeg;base64,sandkansncquiueui3jk
2, ajax + will transfer into space
3, background processing code:
String imgpath = the Server.MapPath ( " ~ / the Img / " ); String newfilename = String .Format ( " {0: the MM-YYYY-mm-dd-HH-SS-FFFF} .jpeg " , the DateTime.Now); / / format is base64 Data: Image / JPEG; base64, sandkansncquiueui3jk String [] = imgStr ImageBase64.Split ( ' , ' ); // Ajax in the transmission will be changed to + space byte [] = imageBytes Convert.FromBase64String ( imgStr [ . 1 ] .Replace ( " " , " + " )); //将base64转为图片 using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) { if (!Directory.Exists(imgPath)) { Directory.CreateDirectory(imgPath); } //1方式 System.Drawing.Bitmap bpmTemp = new System.Drawing.Bitmap(ms); bpmTemp.Save(Path.Combine(imgPath, newFileName)); //2方式 //Image image = Image.FromStream(ms); //image.Save(Path.Combine(imgPath, newFileName)); }
Reference: https: //www.cnblogs.com/dh-hui/p/5387622.html