首页 > 解决方案 > dotnet core -> 返回 jpg 图像的 base64 字符串时 web api 内容类型的最佳实践

问题描述

    [Route("image/{fileName}")]
    [Produces("text/plain or what???")]
    public string image(string fileName)
    {
        byte[] b = fromsomewhere();
        return "data:image/jpg;base64," + Convert.ToBase64String(b);
    }
  1. 我应该在产品中添加什么?

  2. 我应该在响应中包含“data:image/png;base64”,还是应该在客户端上设置?!

我也考虑过使用

 public dynamic image(string fileName)
    {
        byte[] b = fromsomewhere();
        return new FileContentResult(b, "image/jpg");
    }

这是一种更简单的方法和工作,但我仍然很有趣应该为 base64string 设置什么内容类型......

标签: c#.net-corewebapi

解决方案


推荐阅读