Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
32 changes: 32 additions & 0 deletions aspnetcore/fundamentals/minimal-apis/samples/IFormFile/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

// End point to support a single file upload
app.MapGet("/singleFile", () => Results.Text(@"<!DOCTYPE html> <html> <head> <meta charset='utf-8'> </head> <body> <form action='/fileup' method='post' enctype='multipart/form-data'> <input multiple name='formfile' type='file'>Swac <input type='submit'> </form> </body> </html>", "text/html"));

// End point to support multiple file uploads
app.MapGet("/multipleFiles", () => Results.Text(@"<!DOCTYPE html> <html> <head> <meta charset='utf-8'> </head> <body> <form action='/filesup' method='post' enctype='multipart/form-data'> <input multiple name='formfile' type='file'>Swac <input type='submit'> </form> </body> </html>", "text/html"));

app.MapPost("/fileup", async (IFormFile file) =>
{
// save a file
string tempfile = Path.GetTempFileName();
using var stream = File.OpenWrite(tempfile);
await file.CopyToAsync(stream);
return Results.Accepted();
});

app.MapPost("/filesup", async (IFormFileCollection myFiles) =>
{
// save file collections
foreach (var file in myFiles)
{
string tempfile = Path.GetTempFileName();
using var stream = File.OpenWrite(tempfile);
await file.CopyToAsync(stream);
}
return Results.Accepted();
});

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}