我想创建一个像这样的函数......
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SaveImage(string file, string fileName)
{
}
文件是从图像创建的Base64编码字符串,fileName是我想要保存的名称。如何使用此编码字符串将图像写入服务器?
我需要使用BinaryWriter
或TextWriter
还是其他一些?您如何解码数据以允许它正确写入服务器?
答案 0 :(得分:7)
byte[] contents = Convert.FromBase64String(file);
System.IO.File.WriteAllBytes(Server.MapPath(fileName), contents);