-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Unable to use IFormFile with ApiController in 2.1 #8311
Comments
Thanks for contacting us, @mitchellj. |
|
I ran into the same problem. And strangely, when not using any controller parameter and trying to access or iterate Until this is solved, I was able to help myself with a workaround by explicitly stating the name of the form parameter using the
After that for some reason the binding worked. I discovered this behavior by accident after having a hard time getting the file upload from an angular 6 application to work. Hope it helps someone else. The link to the corresponding stackoverflow answer is: https://stackoverflow.com/a/52017637/8007572 |
@Schmaga did the compat switch work for you? |
Sorry I was out of the country for a while, I will be back in a couple of days and try the compat switches and report back. Compatibility was NOT set previously so that is most likely the issue will confirm though. |
@mitchellj feel free to reopen this issue if you still see it after changing the compat version. |
I am also still on vacation. Will check as soon as I am back home.
Am 28.08.2018 23:26 schrieb Pranav K <notifications@github.com>:
@Schmaga<https://github.com/Schmaga> did the compat switch work for you?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#8311 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AG6j0M1Zf4DviMQBizOKeFgZyC54Nzssks5uVbWOgaJpZM4WIau4>.
|
@pranavkm I returned from vacation and checked with the compat switch set to 2.1. It now works, but I also have to remove the I think it might make sense to better document what exactly the compat switch affects, because I would not have thought it would produce such strange behavior as described in my above post. |
That isn't intended. Do you have a repro app for this? |
Not yet, but I could extract it from our project for you. What format is best? Will it be enough to paste the relevant snippets here or do you need a zip file with a project or something? This is my first .NET OSS issue, so sorry if the answer might be obvious. And I didn't find anything specific about providing example code in the contribution guidelines :) |
A sample repo on github works really well to share code. If that's difficult, any of your suggestions work fine. |
Moved to preview3 for now. |
Sorry back now, I can confirm as @pranavkm has found as well that
|
Thanks @pranavkm. Will provide a repo then, hopefully in the next few days. |
Looks like yet another case that we need to special case in https://github.com/aspnet/Mvc/blob/release/2.2/src/Microsoft.AspNetCore.Mvc.Core/Internal/ApiBehaviorApplicationModelProvider.cs#L215-L233. For 2.1, I'd recommend not specifying the attribute or if you do specify the attribute, also specify the name .e.g |
@pranavkm here is the link to the repositry: https://github.com/Schmaga/aspnet_issue_8311 You can play around with removing the compat switch and/or the attribute a bit. A bit late, but I hope it still helps. |
…bound in ApiControllers Fixes #8311
I have made a repo to reproduce the problem and thanks to @dougbu we have found the solution. Let take a look there: https://github.com/ranouf/TestMultipleUpload |
From @mitchellj on Thursday, 09 August 2018 20:06:10
When we are trying to use
IFormFile
it works perfectly when we are not using[ApiController]
, as soon as we introduceApiController
one of two things happens[FromForm]
we get aSerialization
exception which generates aBad Request
response.FromForm
to the IFormFile then it becomesnull
In order to get IFormFile to work we need to remove
ApiController
completely in which case the IFormFile becomes completely propagated correctly.Copied from original issue: dotnet/aspnetcore#3403
The text was updated successfully, but these errors were encountered: