Skip to content

Commit 9a5ccf4

Browse files
authored
Update README.md
1 parent e1c4472 commit 9a5ccf4

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,46 @@ public class List : BaseAsyncEndpoint
189189

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

192+
### File Upload Example
193+
194+
[See Issue 170 for more details](https://github.com/ardalis/ApiEndpoints/issues/170)
195+
196+
```csharp
197+
using Ardalis.ApiEndpoints;
198+
using Microsoft.AspNetCore.Mvc;
199+
200+
namespace SampleEndpointApp.Endpoints.Authors;
201+
202+
public class File : EndpointBaseAsync
203+
.WithRequest<IFormFile>
204+
.WithResult<ActionResult<string[]>>
205+
{
206+
/// <summary>
207+
/// Post author's photo or something
208+
/// </summary>
209+
[HttpPost("api/[namespace]/file")]
210+
public override async Task<ActionResult<string[]>> HandleAsync(
211+
IFormFile file,
212+
CancellationToken cancellationToken = default)
213+
{
214+
string filePath = Path.GetTempFileName();
215+
using (var fileStream = System.IO.File.Create(filePath))
216+
{
217+
await file.CopyToAsync(fileStream, cancellationToken);
218+
}
219+
220+
return new[]
221+
{
222+
filePath,
223+
file.FileName,
224+
file.ContentType,
225+
file.ContentDisposition,
226+
file.Length.ToString()
227+
};
228+
}
229+
}
230+
```
231+
192232
## 4. Animated Screenshots
193233

194234
### Working with Endpoints, Requests, and Results in Visual Studio

0 commit comments

Comments
 (0)