简体   繁体   English

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

[英]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? 我是否需要使用BinaryWriterTextWriter或其他工具? 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.

相关问题 将图像文件从 qrCode 或 base64 保存到 asp.net C# - Save image file from qrCode or base64 in asp.net C# 如何使用 c# webmethod 从通过 ajax 请求传递的 base64 字符串保存图像 - How to save an image from a base64 string passed through ajax request using c# webmethod 如何将 base64 字符串作为图像保存到 C# 的文件夹中? - How to save base64 string as an image into a folder in C#? 在asp.net核心中保存来自结果转换base64字符串的图像 - Save image from result convert base64 string in asp.net core 在使用C#解码Base64字符串之前,是否要删除data:image / jpeg; base64? - Do you remove the data:image/jpeg;base64, before decoding Base64 string using C#? 来自base64的C#Asp.net RazorPdf / iTextSharp图像 - C# Asp.net RazorPdf / iTextSharp image from base64 无法将资源文件中存储的图像转换为Asp.net [C#]中的Base64字符串 - Unable to convert Images stored in resource file to Base64 string in Asp.net [C#] 如何使用 C# 使用 ASP.NET Core 6 MVC 将 Base64 / byte [] 图像上传到 Azure Blob? - How to Uploading Base64 / byte[] Image to Azure Blob with ASP.NET Core 6 MVC using C#? 在C#中将Base64编码的图像作为HTTP响应返回 - Return Base64 Encoded Image As HTTP Response in C# C# Hashing Base64 编码的字符串长度 - C# Hashing Base64 encoded string length
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM