public void ProcessRequest(HttpContext context) { string fileId = context.Request.QueryString["id"]; string cid = context.Request.QueryString["cid"]; byte[] imgByte = null; try { if (string.IsNullOrEmpty(cid)) { imgByte = new BlobBLL().Download(fileId); } else { int countryId = Convert.ToInt32(cid); imgByte = new BlobBLL().Download(fileId, countryId); } } catch (Exception ex) { log4net.ILog log = log4net.LogManager.GetLogger(typeof(BlobHandler)); log.Error(ex); } if (imgByte == null) { imgByte = System.IO.File.ReadAllBytes(context.Server.MapPath("~/Content/Images/NoFileFound.png")); } context.Response.ContentType = "image/jpeg"; context.Response.BinaryWrite(imgByte); context.Response.End(); }
public void Download(string id) { var file = FoundationDB.FileDb.GetById(id); BlobBLL bb = new BlobBLL(); var byteStr = bb.Download(id); if (byteStr != null) { Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.FileName, System.Text.Encoding.UTF8)); Response.BinaryWrite(byteStr); Response.Flush(); Response.End(); } }