Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Dotnet核心->;返回jpg图像的base64字符串时web api内容类型的最佳实践_C#_.net Core_Webapi - Fatal编程技术网

C# Dotnet核心->;返回jpg图像的base64字符串时web api内容类型的最佳实践

C# Dotnet核心->;返回jpg图像的base64字符串时web api内容类型的最佳实践,c#,.net-core,webapi,C#,.net Core,Webapi,我应该放什么 我应该在响应中包含“data:image/png;base64”,还是应该在客户机上设置 我也考虑过使用 [Route("image/{fileName}")] [Produces("text/plain or what???")] public string image(string fileName) { byte[] b = fromsomewhere(); return "data:image/jpg;base

我应该放什么

  • 我应该在响应中包含“data:image/png;base64”,还是应该在客户机上设置

  • 我也考虑过使用

        [Route("image/{fileName}")]
        [Produces("text/plain or what???")]
        public string image(string fileName)
        {
            byte[] b = fromsomewhere();
            return "data:image/jpg;base64," + Convert.ToBase64String(b);
        }
    

    哪种方法更简单,也更有效,但我仍然很感兴趣base64string的内容类型应该设置为什么…

    这是否回答了您的问题@tvdias它不回答我应该为base64string使用哪种内容类型
     public dynamic image(string fileName)
        {
            byte[] b = fromsomewhere();
            return new FileContentResult(b, "image/jpg");
        }