Merge pull request #26822 from dotnet/mutiple-return-types

IFormFile code update
pull/26823/head
Rick Anderson 2022-08-24 16:34:19 -10:00 committed by GitHub
commit 845bc50899
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -1,6 +1,3 @@
using Microsoft.AspNetCore.Http;
using System.IO;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
@ -8,7 +5,8 @@ app.MapGet("/", () => "Hello World!");
app.MapPost("/upload", async (IFormFile file) =>
{
var tempFile = Path.GetTempFileName(); // or an existing custom file path
var tempFile = Path.GetTempFileName();
app.Logger.LogInformation(tempFile);
using var stream = File.OpenWrite(tempFile);
await file.CopyToAsync(stream);
});
@ -17,7 +15,8 @@ app.MapPost("/upload_many", async (IFormFileCollection myFiles) =>
{
foreach (var file in myFiles)
{
var tempFile = Path.GetTempFileName(); // or an existing custom file path
var tempFile = Path.GetTempFileName();
app.Logger.LogInformation(tempFile);
using var stream = File.OpenWrite(tempFile);
await file.CopyToAsync(stream);
}