[英]How do you take an image (passed in as a Base64 encoded string) and save it to the server in Asp.Net C#?
I want to create a function like this... 我想创建一个这样的功能...
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SaveImage(string file, string fileName)
{
}
Where the file is the Base64 encoded string created from the image, and the fileName is the name I want to save it as. 其中文件是从映像创建的Base64编码的字符串,而fileName是我要将其另存为的名称。 How can I use this encoded string to write the image to the server?
如何使用此编码的字符串将图像写入服务器?
Do I need to use BinaryWriter
or TextWriter
or some other one? 我是否需要使用
BinaryWriter
或TextWriter
或其他工具? And how do you decode the data to allow it to write to the server properly? 以及如何解码数据以使其正确写入服务器?
byte[] contents = Convert.FromBase64String(file);
System.IO.File.WriteAllBytes(Server.MapPath(fileName), contents);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.