zoukankan      html  css  js  c++  java
  • asp.net core API 3.1获取图片返回流文件

      [Route("{id}")]
            [HttpGet]
            public FileContentResult Get(string id)
            {
                using (var sw = new FileStream("E://项目//FileImag//20191217//11233aa89256ce39f4e378f58f3bd6e3ac537.jpg", FileMode.Open))
                {
                    var contenttype = GetContentTypeForFileName("E://项目//FileImag//20191217//11233aa89256ce39f4e378f58f3bd6e3ac537.jpg");
                    var bytes = new byte[sw.Length];
                    sw.Read(bytes, 0, bytes.Length);
                    sw.Close();
                    return new FileContentResult(bytes, contenttype);
                }
            }
            /// <summary>
            /// 注册表获取文件类型
            /// </summary>
            /// <param name="fileName"></param>
            /// <returns></returns>
            private string GetContentTypeForFileName(string fileName)
            {
                //获取文件后缀
                string ext = Path.GetExtension(fileName);
                using (Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext))
                {
                    if (registryKey == null)
                        return null;
                    var value = registryKey.GetValue("Content Type");
                    return value?.ToString();
                }
            }
    //直接返回文件
    public IActionResult ShowImage()
    {
      return PhysicalFile(@"c:404.jpg", "image/jpeg");
    }
  • 相关阅读:
    梦幻如初,心不忘。
    整数集和求并
    ACTF 2014 Write up
    适用web的图片
    jqGrid
    angularjs
    【转载】FPGA异步时钟设计中的同步策略
    Cordic的学习之硬件实现
    Cordic的学习初步
    DDS---三角函数发生器的用法
  • 原文地址:https://www.cnblogs.com/zxp6/p/13131334.html
Copyright © 2011-2022 走看看