I have a web service method, which looks like this:
[HttpGet("{id}")]
public ActionResult<byte[]> Get(Guid id)
{
var files = Directory.GetFiles(@"Pictures\");
foreach (var file in files)
{
if (file.Contains(id.ToString()))
{
return System.IO.File.ReadAllBytes(file);
}
}
return null;
}
Here is the client code, which is definitely working i.e. it is calling the web service and the web service is returning the image:
var response2 = await client.GetAsync("http://localhost:59999/api/Images/5c60f693-bef5-e011-a485-80ee7300c692");
byte[] image2 = await response2.Content.ReadAsByteArrayAsync(); //https://stackoverflow.com/questions/39190018/how-to-get-object-using-httpclient-with-response-ok-in-web-api
System.IO.File.WriteAllBytes("image.jpg", image2);
When I try to open image.jpg in Paint; it says it is an invalid file. What is the problem?