怎样将上传的图片以二进制的形式存入用orcal数据库

魑魅玲儿 2014-04-15 09:53:21
用的mvc框架,用EF将数据存入oracl数据库,怎样将图片用二进制存入数据库,然后用文件流取出来,本人是新手,求帮助
...全文
129 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
魑魅玲儿 2014-04-15
  • 打赏
  • 举报
回复
所以不能只要要用到路径的方法都不行
魑魅玲儿 2014-04-15
  • 打赏
  • 举报
回复
用的uploadflash做的上传,怎么把上传的图片转成二进制存入数据库并读取显示,只有IE有路径,其他浏览器都没有
md5e 2014-04-15
  • 打赏
  • 举报
回复
/// <summary> /// 把 Base64 转图片 /// </summary> /// <param name="base64String"></param> public static MemoryStream Base64ToImage(string base64String) { // base64String.Substring(0, base64String.Length / 40 * 40) 主要是 Base64 編碼長度有規定必須是 0 或 4 的整數倍,所以為免出錯,把長度處理一下 byte[] imageBytes = Convert.FromBase64String(base64String); // byte[] imageBytes = Convert.FromBase64String(base64String.Substring(0,128)); MemoryStream _ms = new MemoryStream(imageBytes, 0, imageBytes.Length); // Convert byte[] to Image _ms.Write(imageBytes, 0, imageBytes.Length); /* System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true); image.Save(Server.MapPath("Report"), ImageFormat.Png); */ return _ms; } // 把图片转 Base64 编码 public static string ImageToBase64(System.Drawing.Image image, System.Drawing.Imaging.ImageFormat format) { using (MemoryStream ms = new MemoryStream()) { // Convert Image to byte[] image.Save(ms, format); byte[] imageBytes = ms.ToArray(); // Convert byte[] to Base64 String string base64String = Convert.ToBase64String(imageBytes); return base64String; } } 把图片当然字符串来存储就可以了
md5e 2014-04-15
  • 打赏
  • 举报
回复
可以将图片以bt64格式的字符串来存储
feiyun0112 2014-04-15
  • 打赏
  • 举报
回复
字段对应的EF属性应该是个byte[],你把数据存进去就行了

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧