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

Mat*_*att 2 c# asp.net-mvc base64 encoding file

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

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

    }
Run Code Online (Sandbox Code Playgroud)

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

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

Meh*_*ari 7

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