我已经在我的MVC web应用中浏览并上传了一个png/jpg文件。我已经将这个文件作为byte[]存储在我的数据库中。现在我想读取byte[]并将其转换为原始文件。我如何才能做到这一点?
发布于 2010-06-23 21:27:38
从数据库中的byte[]数组创建内存流,然后使用Image.FromStream。
byte[] image = GetImageFromDatabase();
MemoryStream ms = new MemoryStream(image);
Image i = Image.FromStream(ms);
发布于 2020-10-05 00:56:32
您是否在DotNet Core3.0或更高版本上遇到上述解决方案的问题
所以我的解决方案是:
using(var ms = new MemoryStream(yourByteArray)) {
using(var fs = new FileStream("savePath", FileMode.Create)) {
ms.WriteTo(fs);
}
}
发布于 2021-03-09 02:50:35
或者直接使用这个:
System.IO.File.WriteAllBytes(string path, byte[] bytes)
File.WriteAllBytes(String, Byte[]) Method (System.IO) | Microsoft Docs
https://stackoverflow.com/questions/3102005
复制相似问题