.NET Core IFormFile has problem with FileBufferedReadStream on Post method

Viewed 226

My client side markup:

<form method="post" enctype="multipart/form-data" asp-controller="ProdctionPlans" asp-action="UpdateStock">
    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
    <div class="row">
        <div class="form-group">
            <input type="file" name="formFile" class="form-control-sm">
            <input id="fileSubmit" type="submit" class="btn btn-primary" value="Select file">
            @if (ViewBag.Message != null)
            {
                <p id='fileForm' class='alert alert-info'> @ViewBag.Message</p>
            }
        </div>
    </div>
</form>

Server-side code

[ValidateAntiForgeryToken]
[HttpPost("ProductionPlans/UpdateStock")]
public IActionResult UpdateStock(IFormFile formFile)
{
    // some code
}

On post, the parameter formFile throws an error in the FileBufferedStream

ReadTimeout = '((Microsoft.AspNetCore.Http.Internal.FormFile)formFile)._baseStream.ReadTimeout' threw an exception of type 'System.InvalidOperationException'
WriteTimeout = '((Microsoft.AspNetCore.Http.Internal.FormFile)formFile)._baseStream.WriteTimeout' threw an exception of type 'System.InvalidOperationException'

Stream details:

CanRead true
CanSeek true
CanTimeout  false
CanWrite    false
InMemory    false
Length  69182
Position    69182

Any ideas how to solve it?

0 Answers
Related