admin 发布时间:2018-04-24 分类:.NET 阅读:11260次 5 条评论
public IActionResult GetImg(string code) { #region 设置浏览器缓存header头信息 Response.Headers.Add("Cache-Control", "pulic"); Response.Headers.Add("Last-Modified", DateTime.Now.AddDays(-30).ToString("r")); Response.Headers.Add("Expires", DateTime.Now.AddDays(30).ToString("r")); Response.Headers.Add("ETag", code); #endregion if (string.IsNullOrWhiteSpace(code)) { //返回404信息 return new StatusCodeResult((int)HttpStatusCode.NotFound); } var fileInfo = repository.GetList<B_UploadInfo>(new { FileCode = code }).FirstOrDefault(); if (fileInfo == null) { return new StatusCodeResult((int)HttpStatusCode.NotFound); } try { var filePath = hostingEnv.ContentRootPath + "/wwwroot" + fileInfo.FilePath + fileInfo.FileCode + fileInfo.Extension; var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); var buffur = new byte[fileStream.Length]; fileStream.Read(buffur, 0, (int)fileStream.Length); fileStream.Close(); var fileResult = new FileContentResult(buffur, "image/jpeg"); return fileResult; } catch (Exception ex) { logger.Error($"code:{code}," + ex); return new StatusCodeResult((int)HttpStatusCode.NotFound); } }
发布于 2021-11-09 00:53:04 回复该评论
发布于 2018-06-20 13:52:20 回复该评论
发布于 2018-06-11 02:46:36 回复该评论
发布于 2018-05-02 19:36:24 回复该评论
发表评论:
◎欢迎您的参与讨论。