Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis authored Oct 5, 2023
1 parent e1c4472 commit 9a5ccf4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,46 @@ public class List : BaseAsyncEndpoint

Examples of the configuration can be found in the sample API project

### File Upload Example

[See Issue 170 for more details](https://github.com/ardalis/ApiEndpoints/issues/170)

```csharp
using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Mvc;

namespace SampleEndpointApp.Endpoints.Authors;

public class File : EndpointBaseAsync
.WithRequest<IFormFile>
.WithResult<ActionResult<string[]>>
{
/// <summary>
/// Post author's photo or something
/// </summary>
[HttpPost("api/[namespace]/file")]
public override async Task<ActionResult<string[]>> HandleAsync(
IFormFile file,
CancellationToken cancellationToken = default)
{
string filePath = Path.GetTempFileName();
using (var fileStream = System.IO.File.Create(filePath))
{
await file.CopyToAsync(fileStream, cancellationToken);
}

return new[]
{
filePath,
file.FileName,
file.ContentType,
file.ContentDisposition,
file.Length.ToString()
};
}
}
```

## 4. Animated Screenshots

### Working with Endpoints, Requests, and Results in Visual Studio
Expand Down

0 comments on commit 9a5ccf4

Please sign in to comment.