Hello,
The [FromForm] IFormFile file is null for a REST API HttpPost.
The project was created using the Visual Studio 2022 ASP.NET Core Web API template.
I deleted the Weather model and controller. And added my own controller.
Here is my controller code:
using Microsoft.AspNetCore.Mvc;
using DocumentChunker;
namespace DocumentChunkerRestAPI.Controllers
{
public class ChunkerController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost("chunk")]
public IActionResult Chunk([FromForm] IFormFile file, [FromForm] int iParseType)
{
if (file == null || file.Length == 0)
{
return BadRequest("File not provided");
}
if (iParseType < 0 || iParseType > 2)
{
return BadRequest("Parse types are from 0 - 2");
}
var json = string.Empty;
// Process the file and the integer as needed
using (var memoryStream = new MemoryStream())
{
file.CopyTo(memoryStream);
ParseType parseType = ParseType.SENTENCE;
if (iParseType == 0)
{
parseType = ParseType.SENTENCE;
}
else if (iParseType == 1)
{
parseType = ParseType.PARAGRAPH;
}
else if (iParseType == 2)
{
parseType = ParseType.PAGE;
}
json = new DocumentChunker.Chunker().Chunk(memoryStream, parseType, file.FileName);
}
return new JsonResult(json)
{
ContentType = "application/json",
StatusCode = 200
};
}
}
}
Any suggestions?
williamj