1 implementation of IFormFile
Microsoft.AspNetCore.Http (1)
FormFile.cs (1)
9public class FormFile : IFormFile
287 references to IFormFile
BasicWebSite (1)
Controllers\ReadFromThrowingRequestBodyController .cs (1)
15public IActionResult ReadForm(Person person, IFormFile form)
FilesWebSite (2)
Models\Product.cs (1)
10public IDictionary<string, IEnumerable<IFormFile>> Specs { get; set; }
Models\User.cs (1)
10public IFormFile Biography { get; set; }
HtmlGenerationWebSite (2)
Models\Folder.cs (2)
8public IFormFile InterfaceFile { get; set; } 16public IEnumerable<IFormFile> EnumerableFiles { get; set; }
Microsoft.AspNetCore.Components.Endpoints (10)
FormMapping\BrowserFileFromFormFile.cs (1)
10internal sealed class BrowserFileFromFormFile(IFormFile formFile) : IBrowserFile
FormMapping\Converters\FileConverter.cs (3)
28var targetFile = reader.FormFileCollection.GetFile(reader.CurrentPrefix.ToString()); 52if (typeof(T) == typeof(IReadOnlyList<IFormFile>)) 74var file = formFileCollection.GetFile(reader.CurrentPrefix.ToString());
FormMapping\Factories\FileConverterFactory.cs (2)
22private static bool CanConvertCommon(Type type) => type == typeof(IFormFile) || type == typeof(IFormFileCollection) || type == typeof(IReadOnlyList<IFormFile>);
FormMapping\WellKnownConverters.cs (4)
47{ typeof(IFormFile), new FileConverter<IFormFile>() }, 48{ typeof(IReadOnlyList<IFormFile>), new FileConverter<IReadOnlyList<IFormFile>>() },
Microsoft.AspNetCore.Components.Endpoints.Tests (4)
Binding\FormDataMapperTests.cs (4)
1917var result = CallDeserialize(reader, options, typeof(IFormFile)); 1945var result = CallDeserialize(reader, options, typeof(IReadOnlyList<IFormFile>)); 1948var formFileResult = Assert.IsAssignableFrom<IReadOnlyList<IFormFile>>(result); 1978var result = CallDeserialize(reader, options, typeof(IFormFile));
Microsoft.AspNetCore.Http (8)
FormFile.cs (1)
7/// Default implementation of <see cref="IFormFile"/>.
FormFileCollection.cs (7)
9public class FormFileCollection : List<IFormFile>, IFormFileCollection 12public IFormFile? this[string name] => GetFile(name); 15public IFormFile? GetFile(string name) 17foreach (var file in this) 29public IReadOnlyList<IFormFile> GetFiles(string name) 31var files = new List<IFormFile>(); 33foreach (var file in this)
Microsoft.AspNetCore.Http.Extensions (11)
RequestDelegateFactory.cs (3)
767else if (parameter.ParameterType == typeof(IFormFile)) 854else if (parameter.ParameterType == typeof(IFormFile)) 2254var valueExpression = GetValueFromProperty(FormFilesExpr, FormFilesIndexerProperty, key, typeof(IFormFile));
src\Components\Endpoints\src\FormMapping\Converters\FileConverter.cs (2)
52if (typeof(T) == typeof(IReadOnlyList<IFormFile>)) 74var file = formFileCollection.GetFile(reader.CurrentPrefix.ToString());
src\Components\Endpoints\src\FormMapping\Factories\FileConverterFactory.cs (2)
22private static bool CanConvertCommon(Type type) => type == typeof(IFormFile) || type == typeof(IFormFileCollection) || type == typeof(IReadOnlyList<IFormFile>);
src\Components\Endpoints\src\FormMapping\WellKnownConverters.cs (4)
47{ typeof(IFormFile), new FileConverter<IFormFile>() }, 48{ typeof(IReadOnlyList<IFormFile>), new FileConverter<IReadOnlyList<IFormFile>>() },
Microsoft.AspNetCore.Http.Extensions.Tests (30)
RequestDelegateFactoryTests.cs (9)
1926void TestAction(IFormFile file) 1990void TestFormFileAndJson(IFormFile value1, Todo value2) { } 1991void TestFormFilesAndJson(IFormFile value1, IFormFile value2, Todo value3) { } 1993void TestFormFileAndJsonWithAttribute(IFormFile value1, [FromBody] int value2) { } 1996void TestJsonAndFormFile(Todo value1, IFormFile value2) { } 1997void TestJsonAndFormFiles(Todo value1, IFormFile value2, IFormFile value3) { } 1999void TestJsonAndFormFileWithAttribute(Todo value1, [FromForm] IFormFile value2) { }
RequestDelegateFactoryTests.FormMapping.cs (2)
321public IFormFile? File { get; set; } 322public IReadOnlyList<IFormFile>? FormFiles { get; set; }
RequestDelegateGenerator\RequestDelegateCreationTests.Forms.cs (19)
112var fileArgument = Assert.IsAssignableFrom<IFormFile>(httpContext.Items["formFiles"]); 150var fileArgument = Assert.IsAssignableFrom<IFormFile>(httpContext.Items["formFiles"]); 188var file1Argument = Assert.IsAssignableFrom<IFormFile>(httpContext.Items["file1"]); 193var file2Argument = Assert.IsAssignableFrom<IFormFile>(httpContext.Items["file2"]); 266var fileArgument = Assert.IsAssignableFrom<IFormFile>(httpContext.Items["formFiles"]); 303var fileArgument = Assert.IsAssignableFrom<IFormFile>(httpContext.Items["formFiles"]); 326var factoryResult = RequestDelegateFactory.Create((HttpContext context, IFormFile file) => 413var fileArgument = Assert.IsAssignableFrom<IFormFile>(httpContext.Items["file"]); 460var fileArgument = Assert.IsAssignableFrom<IFormFile>(httpContext.Items["file"]); 505var fileArgument = Assert.IsAssignableFrom<IFormFile>(httpContext.Items["file"]);
Microsoft.AspNetCore.Http.Features (4)
IFormFileCollection.cs (4)
9public interface IFormFileCollection : IReadOnlyList<IFormFile> 18IFormFile? this[string name] { get; } 27IFormFile? GetFile(string name); 38IReadOnlyList<IFormFile> GetFiles(string name);
Microsoft.AspNetCore.Http.Tests (4)
Features\FormFeatureTests.cs (4)
300var file = formCollection.Files["myfile1"]; 385var file = formCollection.Files["myfile1"]; 434var file = formCollection.Files["myfile1"]; 583var file = formCollection.Files["myfile1"];
Microsoft.AspNetCore.Mvc.Abstractions (1)
ModelBinding\BindingSource.cs (1)
99/// A <see cref="BindingSource"/> for <see cref="IFormFile"/>, <see cref="IFormCollection"/>, and <see cref="IFormFileCollection"/>.
Microsoft.AspNetCore.Mvc.ApiExplorer (1)
EndpointMetadataApiDescriptionProvider.cs (1)
303else if (parameterType == typeof(IFormFile) || parameterType == typeof(IFormFileCollection))
Microsoft.AspNetCore.Mvc.ApiExplorer.Test (18)
DefaultApiDescriptionProviderTest.cs (1)
2452private void AcceptsFormFile([FromFormFile] IFormFile formFile)
EndpointMetadataApiDescriptionProviderTest.cs (17)
1187builder.MapPost("/file/upload", (IFormFile formFile) => ""); 1200Assert.Equal(typeof(IFormFile), bodyParameterDescription.Type); 1216builder.MapPost("/file/upload", (IFormFile? inferredFormFile) => ""); 1229Assert.Equal(typeof(IFormFile), bodyParameterDescription.Type); 1245builder.MapPost("/file/upload", (IFormFile file) => Results.NoContent()); 1258Assert.Equal(typeof(IFormFile), bodyParameterDescription.Type); 1273[Consumes("application/custom0", "application/custom1")] (IFormFile file) => Results.NoContent()); 1289var apiDescription0 = GetApiDescription((IFormFile fromFile) => { }); 1290var apiDescription1 = GetApiDescription((IFormFile? fromFile) => { }); 1295Assert.Equal(typeof(IFormFile), fromFileParam0.Type); 1296Assert.Equal(typeof(IFormFile), fromFileParam0.ModelMetadata.ModelType); 1301Assert.Equal(typeof(IFormFile), fromFileParam1.Type); 1302Assert.Equal(typeof(IFormFile), fromFileParam1.ModelMetadata.ModelType); 1319AssertFormFileParameter(GetApiDescription((IFormFile file) => { }), typeof(IFormFile), "file"); 1320AssertFormFileParameter(GetApiDescription(([FromForm(Name = "file_name")] IFormFile file) => { }), typeof(IFormFile), "file_name");
Microsoft.AspNetCore.Mvc.Core (35)
ApiBehaviorOptions.cs (1)
42/// Parameters of type <see cref="IFormFile"/> and <see cref="IFormFileCollection"/> are assumed to be bound from form.
Infrastructure\MvcCoreMvcOptionsSetup.cs (3)
117modelMetadataDetailsProviders.Add(new BindingSourceMetadataProvider(typeof(IFormFile), BindingSource.FormFile)); 120modelMetadataDetailsProviders.Add(new BindingSourceMetadataProvider(typeof(IEnumerable<IFormFile>), BindingSource.FormFile)); 131modelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(IFormFile)));
ModelBinding\Binders\FormCollectionModelBinder.cs (5)
88private sealed class EmptyFormFileCollection : List<IFormFile>, IFormFileCollection 90public IFormFile? this[string name] => null; 92public IFormFile? GetFile(string name) => null; 94IReadOnlyList<IFormFile> IFormFileCollection.GetFiles(string name) => Array.Empty<IFormFile>();
ModelBinding\Binders\FormFileModelBinder.cs (21)
16/// <see cref="IModelBinder"/> implementation to bind posted files to <see cref="IFormFile"/>. 41if (!createFileCollection && !ModelBindingHelper.CanGetCompatibleCollection<IFormFile>(bindingContext)) 47ICollection<IFormFile> postedFiles; 50postedFiles = new List<IFormFile>(); 54postedFiles = ModelBindingHelper.GetCompatibleCollection<IFormFile>(bindingContext); 80if (bindingContext.ModelType == typeof(IFormFile)) 103if (modelType == typeof(IFormFile[])) 105Debug.Assert(postedFiles is List<IFormFile>); 106value = ((List<IFormFile>)postedFiles).ToArray(); 110Debug.Assert(postedFiles is List<IFormFile>); 111value = new FileCollection((List<IFormFile>)postedFiles); 138ICollection<IFormFile> postedFiles) 145foreach (var file in form.Files) 170private sealed class FileCollection : ReadOnlyCollection<IFormFile>, IFormFileCollection 172public FileCollection(List<IFormFile> list) 177public IFormFile? this[string name] => GetFile(name); 179public IFormFile? GetFile(string name) 183var file = Items[i]; 193public IReadOnlyList<IFormFile> GetFiles(string name) 195var files = new List<IFormFile>(); 198var file = Items[i];
ModelBinding\Binders\FormFileModelBinderProvider.cs (4)
13/// An <see cref="IModelBinderProvider"/> for <see cref="IFormFile"/>, collections 14/// of <see cref="IFormFile"/>, and <see cref="IFormFileCollection"/>. 25if (modelType == typeof(IFormFile) || 27typeof(IEnumerable<IFormFile>).IsAssignableFrom(modelType))
ModelBinding\FormFileValueProvider.cs (1)
47var file = formFiles[i];
Microsoft.AspNetCore.Mvc.Core.Test (47)
ApplicationModels\ConsumesConstraintForFormFileParameterConventionTest.cs (2)
79public IActionResult FormFileParameter(IFormFile formFile) => null; 85public IActionResult FormFileSequenceParameter(IFormFile[] formFiles) => null;
ApplicationModels\DefaultApplicationModelProviderTest.cs (6)
1777public IFormFile FormFile { get; set; } 1782IEnumerable<IFormFile> formFileEnumerable, 1783ICollection<IFormFile> formFileCollection, 1784IList<IFormFile> formFileIList, 1785List<IFormFile> formFileList, 1786IFormFile[] formFileArray) => null;
ApplicationModels\InferParameterBindingInfoConventionTest.cs (7)
980public IActionResult FormFileParameter(IFormFile formFile) => null; 986public IActionResult FormFileSequenceParameter(IFormFile[] formFiles) => null; 1048public IActionResult FromFormFormFileParameters([FromForm] IFormFile p1, [FromForm] IFormFile[] p2, [FromForm] IFormFileCollection p3) => null; 1050public IActionResult FormFileParameters(IFormFile p1, IFormFile[] p2, IFormFileCollection p3) => null; 1165public IList<IFormFile> Files { get; set; }
ModelBinding\Binders\FormFileModelBinderProviderTest.cs (4)
30[InlineData(typeof(IFormFile))] 31[InlineData(typeof(IFormFile[]))] 33[InlineData(typeof(IEnumerable<IFormFile>))] 34[InlineData(typeof(Collection<IFormFile>))]
ModelBinding\Binders\FormFileModelBinderTest.cs (28)
22var bindingContext = GetBindingContext(typeof(IEnumerable<IFormFile>), httpContext); 54new EmptyModelMetadataProvider().GetMetadataForType(typeof(IFormFile)), 169new EmptyModelMetadataProvider().GetMetadataForType(typeof(IFormFile)), 205new EmptyModelMetadataProvider().GetMetadataForType(typeof(IFormFile)), 229var bindingContext = GetBindingContext(typeof(IEnumerable<IFormFile>), httpContext); 243var files = Assert.IsAssignableFrom<IList<IFormFile>>(bindingContext.Result.Model); 248[InlineData(typeof(IFormFile[]))] 249[InlineData(typeof(ICollection<IFormFile>))] 250[InlineData(typeof(IList<IFormFile>))] 252[InlineData(typeof(List<IFormFile>))] 253[InlineData(typeof(LinkedList<IFormFile>))] 270Assert.Equal(formFiles, bindingContext.Result.Model as IEnumerable<IFormFile>); 279var bindingContext = GetBindingContext(typeof(IFormFile), httpContext); 287var file = Assert.IsAssignableFrom<IFormFile>(bindingContext.Result.Model); 297var bindingContext = GetBindingContext(typeof(IFormFile), httpContext); 317var bindingContext = GetBindingContext(typeof(IFormFile), httpContext); 341var bindingContext = GetBindingContext(typeof(IFormFile), httpContext); 353var file = Assert.IsAssignableFrom<IFormFile>(bindingContext.Result.Model); 364new Mock<IFormFile>().Object 367var bindingContext = GetBindingContext(typeof(IFormFile), httpContext); 387var bindingContext = GetBindingContext(typeof(IFormFile), httpContext); 422var bindingContext = GetBindingContext(typeof(ISet<IFormFile>), httpContext); 499private static IFormFile GetMockFormFile(string modelName, string filename) 501var formFile = new Mock<IFormFile>(); 510public IFormFile[] ArrayProperty { get; } 513private class FileList : List<IFormFile>
Microsoft.AspNetCore.Mvc.IntegrationTests (49)
BindingSourceMetadataProviderIntegrationTest.cs (1)
118public IFormFile File { get; set; }
ComplexRecordIntegrationTest.cs (6)
488private record Person4(string Name, IEnumerable<IFormFile> Documents); 685var document = Assert.Single(model.Customer.Documents); 742var document = Assert.Single(model.Customer.Documents); 2963private record Person5(string Name, IFormFile Photo); 3102private record Person6(string Name, Person6 Mother, IFormFile Photo); 3225private record Person7(string Name, IList<Person7> Children, IFormFile Photo);
ComplexTypeIntegrationTestBase.cs (6)
490public IEnumerable<IFormFile> Documents { get; set; } 688var document = Assert.Single(model.Customer.Documents); 745var document = Assert.Single(model.Customer.Documents); 3170public IFormFile Photo { get; set; } 3323public IFormFile Photo { get; set; } 3453public IFormFile Photo { get; set; }
FormCollectionModelBindingIntegrationTest.cs (2)
60var file = Assert.Single(formCollection.Files); 107var file = Assert.Single(formCollection.Files);
FormFileModelBindingIntegrationTest.cs (32)
23public IFormFile File { get; set; } 59var file = Assert.IsAssignableFrom<IFormFile>(boundPerson.Address.File); 106var file = Assert.IsAssignableFrom<IFormFile>(boundPerson.Address.File); 157var file = Assert.IsAssignableFrom<IFormFile>(boundPerson.Address.File); 219var file = Assert.IsAssignableFrom<IFormFile>(boundPerson.Address.File); 265public IFormFile Spec { get; set; } 308var file = Assert.IsAssignableFrom<IFormFile>(vehicle.Spec); 375var file = Assert.IsAssignableFrom<IFormFile>(vehicle.BackupVehicle.Spec); 437var file = Assert.IsAssignableFrom<IFormFile>(boundPerson.Address.File); 468public List<IFormFile> ListProperty { get; set; } 498var file = Assert.Single(boundContainer.ListProperty); 552public List<IFormFile> ListProperty { get; } = new List<IFormFile> 587var file = Assert.Single(boundContainer.ListProperty); 619ParameterType = typeof(IFormFile) 668ParameterType = typeof(IFormFile) 728var file = Assert.Single(car.Specs); 795var file = Assert.Single(car.Specs); 803var file = Assert.Single(car.Specs); 860var file = Assert.Single(car.Specs); 868var file = Assert.Single(car.Specs); 1015var file = Assert.Single(car.Specs); 1033public IFormFile[][] FormFiles { get; set; } 1188public Dictionary<string, IFormFile> Dictionary { get; set; } 1244private static string ReadFormFile(IFormFile file)
TryUpdateModelIntegrationTest.cs (2)
1053var model = new List<IFormFile> 1067var file = Assert.Single(model);
Microsoft.AspNetCore.Mvc.TagHelpers (1)
InputTagHelper.cs (1)
51{ nameof(IFormFile), "file" },
Microsoft.AspNetCore.Mvc.TagHelpers.Test (1)
InputTagHelperTest.cs (1)
1735{ nameof(IFormFile), null, "file" },
Microsoft.AspNetCore.Mvc.Test (3)
MvcOptionsSetupTest.cs (3)
181Assert.Equal(typeof(IFormFile), formFileParameter.Type); 199Assert.Equal(typeof(IEnumerable<IFormFile>), formFileParameter.Type); 245Assert.Equal(typeof(IFormFile), excludeFilter.Type);
Microsoft.AspNetCore.Mvc.ViewFeatures (8)
TemplateRenderer.cs (8)
20public const string IEnumerableOfIFormFileName = "IEnumerable`" + nameof(IFormFile); 67{ typeof(IFormFile).Name, DefaultEditorTemplates.FileInputTemplate }, 174if (typeof(IEnumerable<IFormFile>) != fieldType) 217if (typeof(IEnumerable<IFormFile>).IsAssignableFrom(fieldType)) 222if (typeof(IEnumerable<IFormFile>) == fieldType) 230else if (typeof(IFormFile) != fieldType && typeof(IFormFile).IsAssignableFrom(fieldType)) 232yield return nameof(IFormFile);
Microsoft.AspNetCore.Mvc.ViewFeatures.Test (5)
DefaultEditorTemplatesTest.cs (1)
83{ typeof(IFormFile).Name, "__TextBox__ class='text-box single-line' type='file'" },
TemplateRendererTest.cs (4)
32{ typeof(IFormFile), new string[] { "IFormFile", "Object" } }, 34{ typeof(FormFileCollection), new string[] { "FormFileCollection", typeof(List<IFormFile>).Name, 38{ typeof(IEnumerable<IFormFile>), new string[] { TemplateRenderer.IEnumerableOfIFormFileName, 39typeof(IEnumerable<IFormFile>).Name, "Collection", "Object" } },
Microsoft.AspNetCore.OpenApi (6)
Extensions\JsonTypeInfoExtensions.cs (1)
33[typeof(IFormFile)] = "IFormFile",
Services\OpenApiDocumentService.cs (1)
525if (description.Type == typeof(IFormFile) || description.Type == typeof(IFormFileCollection))
Services\OpenApiGenerator.cs (2)
296var isFormType = requestBodyParameter.ParameterType == typeof(IFormFile) || requestBodyParameter.ParameterType == typeof(IFormFileCollection); 446else if (parameter.ParameterType == typeof(IFormFile) || parameter.ParameterType == typeof(IFormFileCollection))
Services\Schemas\OpenApiSchemaService.cs (1)
64if (type == typeof(IFormFile) || type == typeof(Stream) || type == typeof(PipeReader))
Services\Schemas\OpenApiSchemaStore.cs (1)
21[new OpenApiSchemaKey(typeof(IFormFile), null)] = new JsonObject
Microsoft.AspNetCore.OpenApi.Tests (26)
Extensions\JsonTypeInfoExtensionsTests.cs (1)
44[typeof(IFormFile), "IFormFile"],
Services\OpenApiDocumentService\OpenApiDocumentServiceTests.Parameters.cs (1)
155builder.MapPost("/api/users", (IFormFile formFile, IFormFileCollection formFiles) => { });
Services\OpenApiDocumentService\OpenApiDocumentServiceTests.RequestBody.cs (12)
24builder.MapPost("/", ([FromForm] IFormFile formFile) => { }); 28builder.MapPost("/", (IFormFile formFile) => { }); 62builder.MapPost("/", (IFormFile? formFile) => { }); 66builder.MapPost("/", (IFormFile formFile) => { }); 173builder.MapPost("/", (IFormFile formFile1, IFormFile formFile2) => { }); 213builder.MapPost("/", (IFormFile formFile) => { }).Accepts(typeof(IFormFile), "application/magic-foo-content-type"); 240builder.MapPost("/", [Consumes(typeof(IFormFile), "application/magic-foo-content-type")] (IFormFile formFile) => { }); 951builder.MapGet("/api/", ([FromForm] Todo todo, IFormFile formFile, [FromForm] Guid guid) => { }); 1076private void ActionWithMixedFormTypes([FromForm] Todo todo, IFormFile formFile, [FromForm] Guid guid) { }
Services\OpenApiGeneratorTests.cs (8)
744var operation = GetOpenApiOperation((IFormFile inferredFormFile) => ""); 758var operation = GetOpenApiOperation((IFormFile? inferredFormFile) => ""); 772var operation = GetOpenApiOperation((IFormFile file) => Results.NoContent()); 786[Consumes("application/custom0", "application/custom1")] (IFormFile file) => Results.NoContent()); 805var operation0 = GetOpenApiOperation((IFormFile fromFile) => { }); 806var operation1 = GetOpenApiOperation((IFormFile? fromFile) => { }); 832AssertFormFileParameter(GetOpenApiOperation((IFormFile file) => { }), "object", "file"); 833AssertFormFileParameter(GetOpenApiOperation(([FromForm(Name = "file_name")] IFormFile file) => { }), "object", "file_name");
Shared\SharedTypes.cs (1)
19internal record ResumeUpload(string Name, string Description, IFormFile Resume);
Transformers\Implementations\OpenApiSchemaReferenceTransformerTests.cs (3)
21builder.MapPost("/api", (IFormFile value) => { }); 22builder.MapPost("/api-2", (IFormFile value) => { }); 183builder.MapPost("/api", (IFormFile resume, [FromForm] Todo todo) => { });
Microsoft.AspNetCore.Routing.FunctionalTests (2)
MinimalFormTests.cs (2)
711app.UseEndpoints(b => b.MapPost("/", (IFormFile formFile) => "ok").DisableAntiforgery()); 738app.UseEndpoints(b => b.MapPost("/", (IFormFile formFile) => "ok").DisableAntiforgery());
RazorPagesWebSite (3)
Pages\PropertyBinding\BindFormFile.cshtml.cs (3)
14public IFormFile Form3 { get; set; } 46public IFormFile Form1 { get; set; } 48public IFormFile Form2 { get; set; }
Sample (4)
Program.cs (3)
56forms.MapPost("/form-file", (IFormFile resume) => Results.Ok(resume.FileName)); 58forms.MapPost("/form-file-multiple", (IFormFile resume, IFormFileCollection files) => Results.Ok(files.Count + resume.FileName)); 64forms.MapPost("/forms-pocos-and-files", ([FromForm] Todo todo, IFormFile file) => Results.Ok(new { Todo = todo, File = file.FileName }));
src\OpenApi\test\Microsoft.AspNetCore.OpenApi.Tests\Shared\SharedTypes.cs (1)
19internal record ResumeUpload(string Name, string Description, IFormFile Resume);
SimpleWebSiteWithWebApplicationBuilder (1)
Program.cs (1)
50app.MapPost("/fileupload", async (IFormFile file) =>