locked
ASP.Net API that takes a IFormFIle shuts down IISExpress on execution RRS feed

  • Question

  • User100248066 posted

    I think I am missing something obvious here, but I don't know what.  The project is a ASP.Net Core 3.1 API service which needs to allow another program send it files upwards of 15M.  Here is the controller signature that I have so far:

    [Route("api/[controller]")]
    [ApiController]
    public class ImportController : Controller
    {
    	public ImportController()
    	{
    	}
    
    	[HttpPost]
    	[Route("[action]")]
    	public InitializeResponse Initialize([FromBody] InitializeRequest request)
    	{
    		return new InitializeResponse { Success = false };
    	}
    	
    	[HttpPost]
    	[Route("[action]")]
    	public async Task<ImportRuleResponse> ImportRule([FromForm] IFormFile formFile) //ImportRuleRequest request)
    	{
    		return Ok(new { Success = true });
    	}	
    
    	[HttpPost("FileUpload_ImportRule")]
    	[DisableFormValueModelBinding]
    	public async Task<IActionResult> FileUpload_ImportRule(IFormFile file)
    	{
             return Ok(new { Success = true });
    	}
    }

    When testing this in Swagger, the Initialize() executes fine.  Both the other API's result in Swagger giving a button to pick the file.  Immediately after selecting the file to upload the application crashes, BEFORE I press execute.  Is there some other configuration I need to be doing?

    Thursday, May 13, 2021 8:55 PM

Answers

  • User100248066 posted

    When I returned to this the next day (I always shutdown my PC for the night) all worked.  I made no code changes, all is good today.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 11:57 AM

All replies

  • User-2054057000 posted

    Change it to:

    [HttpPost("FileUpload_ImportRule")]
    public async Task<IActionResult> FileUpload_ImportRule([FromForm]IFormFile file)
    {
    return Ok(new { Success = true });
    }

    You can also refer this article - ASP.NET Core Web API to Upload Files 

    Friday, May 14, 2021 6:04 AM
  • User1686398519 posted

    Hi scarleton, 

    You can enable and view stdout logs.Find the specific problem by looking at the log file.

    You can check this official link to learn how to Troubleshoot on IIS.

    Best Regards,

    YihuiSun

    Friday, May 14, 2021 6:39 AM
  • User100248066 posted

    When I returned to this the next day (I always shutdown my PC for the night) all worked.  I made no code changes, all is good today.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 11:57 AM