如何获取图像(以Base64编码的字符串传递)并将其保存到Asp.Net C#中的服务器?

时间:2009-06-26 18:02:10

标签: c# asp.net-mvc encoding file base64

我想创建一个像这样的函数......

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult SaveImage(string file, string fileName)
    {

    }

文件是从图像创建的Base64编码字符串,fileName是我想要保存的名称。如何使用此编码字符串将图像写入服务器?

我需要使用BinaryWriterTextWriter还是其他一些?您如何解码数据以允许它正确写入服务器?

1 个答案:

答案 0 :(得分:7)

byte[] contents = Convert.FromBase64String(file);
System.IO.File.WriteAllBytes(Server.MapPath(fileName), contents);