标签:request tin code stream 图片 write 日记 sage ring
Controller层
public JsonResult DataSpecialAttachmentImage(HttpPostedFileBase fileData) { //获取页面上的内容名字 string infoname = Convert.ToString(Request["Data_Special_Name"]); //再设置内容名字格式和当前创建时间 string filename = fileData.FileName.Insert(fileData.FileName.LastIndexOf(‘.‘), "_" + infoname + "_" + DateTime.Now.ToString("yyyyMMddHHmmss")); //设置保存的路径 string localPath = Server.MapPath(@"\Content\UploadImages\") + filename; FileInfo file = new FileInfo(localPath); if (!file.Exists) { Stream stream = new FileStream(localPath, FileMode.Create); byte[] bArr = new byte[1024]; int size = fileData.InputStream.Read(bArr, 0, (int)bArr.Length); while (size > 0) { stream.Write(bArr, 0, size); size = fileData.InputStream.Read(bArr, 0, (int)bArr.Length); } stream.Close(); var result = new { State = "Success", FileName = filename }; return Json(result, JsonRequestBehavior.AllowGet); } else { var result = new { State = "Exites", Message = "文件已存在!" }; return Json(result, JsonRequestBehavior.AllowGet); } }
因用的是datatable框架 ,就写View层只写部分视图代码
"render": function (data, type, row) { return "<img src=‘/Content/UploadImages/" + row.Data_Image + "‘ width=‘60px‘/>" }, "targets": 5
《工作日记》 2019-01-18 在程序中图片显示(上传图片)
标签:request tin code stream 图片 write 日记 sage ring
原文地址:https://www.cnblogs.com/zlkkkkkk/p/10325960.html