text:
Q: How to transfer an image via REST API? (Core 2.0 inside) I'm trying to create an Authentication App with ASP.NET Core 2.0, and I'm trying to create some REST methods. What I want to do is to create a GET method that returns the Profile Image. I got this:
[Produces("application/json")]
public class UserController : Controller
{
    private readonly UserManager<ApplicationUser> _userManager;

    public UserProfileController(UserManager<ApplicationUser> userManager)
    {
        _userManager = userManager;
    }

    [HttpGet]
    public async Task<IActionResult> GetPicture(string username)
    {
        var user = await _userManager.FindByNameAsync(username);

        return Ok(user.Picture);
    }
}

And it actually works. The fact is that calling this method return the base64 string representation of my image. But what I want is to get the Image itself. Then, I tried to change the GetPicture method to this:
    [HttpGet]
    public async Task<IActionResult> GetPicture(string username)
    {
        var user = await _userManager.FindByNameAsync(username);

        var bytes = Convert.FromBase64String(user.Picture);
        Image image;
        using (var ms = new MemoryStream(bytes))
        {
            image = Image.FromStream(ms);
        }
        return Ok(image);
    }

But it doesn't work as I hoped. I supposed it is a problem of Content-type, so I tried to change the [Produces("application/json") to [Produces("image/jpeg") or something similar. But it doesn't work, since it gives me back a 406 Error: Not Acceptable. I'm running out of ideas, so I'm asking you if you can help me out with this problem. Thank you in advance!

A: If you want the image returned, then simply return the bytes with the appropriate mimetype. Returning an OkResult is going to cause whatever object you pass in to be serialized and the whole response sent as application/json, which obviously is not an image. This is all you need:
[HttpGet]
public async Task<IActionResult> GetPicture(string username)
{
    var user = await _userManager.FindByNameAsync(username);
    var bytes = Convert.FromBase64String(user.Picture);
    return File(bytes, "image/jpeg");
}