I have RESTful API that returns some large JSON files. I want to save the content to a file before sending it to the client. Here's my endpoint now:
[HttpPost]
[Route("rest/result")]
public IActionResult GetResult(string requestId)
{
var item = _service.GetItem(requestId);
return item?.Result == null ? NotFound() : Ok(item.Result);
}
I tried this code:
[HttpPost]
[Route("rest/result")]
public async Task<IActionResult> GetResult(string requestId)
{
var item = _service.GetItem(requestId);
var str = JsonSerializer.Serialize(item.Result);
await File.WriteAllTextAsync($"c:\\output\\{requestId}.json", str);
return item?.Result == null ? NotFound() : Ok(item.Result);
}
But the file is a bit different. Probably in terms of encoding because I'm seeing things such as : "Data":"{\u0027FnId\u0027:\u002710000149\u0027 in the file.