File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,46 @@ public class List : BaseAsyncEndpoint
189
189
190
190
Examples of the configuration can be found in the sample API project
191
191
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
+
192
232
## 4. Animated Screenshots
193
233
194
234
### Working with Endpoints, Requests, and Results in Visual Studio
You can’t perform that action at this time.
0 commit comments