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

 

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

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);
}

 

posted @ 2018-10-08 15:26  LowKeyC  阅读(1190)  评论(0编辑  收藏  举报
有志者事竟成破釜沉舟百二秦关终属楚苦心人,天不负,卧薪尝胆,三千越甲可吞吴