C# 其他的Url 文件的路径转化为二进制流

时间:2018-10-08 15:38:32   收藏:0   阅读:419

 

//将虚拟路径转化为文件的路径然后最后转化为文件流

public ActionResult SaveImage(string path)
{
var url =System.Web.HttpContext.Current.Request.PhysicalApplicationPath + path;

FileStream fs = new FileStream(url, FileMode.Open, FileAccess.Read); //将图片以文件流的形式进行保存
BinaryReader br = new BinaryReader(fs);
byte[] imgBytesIn = br.ReadBytes((int)fs.Length); //将流读入到字节数组中
Encoding myEncoding = Encoding.GetEncoding("utf-8");
string stImageByte = Convert.ToBase64String(imgBytesIn);

return Json(stImageByte);
}

 

原文:https://www.cnblogs.com/LowKeyCXY/p/9754626.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!