-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileModule.cs
33 lines (27 loc) · 1.05 KB
/
FileModule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Linq;
using System.Threading.Tasks;
namespace Nancy.Demos.Figaro
{
//to upload a file: curl --verbose -F name=comments -F [email protected] http://localhost:3579/file
/// <summary>
/// Uploads the StackExchange files into the database.
/// </summary>
/// <seealso cref="http://bytefish.de/blog/file_upload_nancy/"/>
public class FileModule: NancyModule
{
private readonly FigaroDataContext context;
private readonly IFileUploadHandler handler;
public FileModule(FigaroDataContext dataContext, IFileUploadHandler fileHandler)
{
handler = fileHandler;
context = dataContext;
Post("/file", o => {
var file = Request.Files.FirstOrDefault();
if (file == null) return new Response { StatusCode = HttpStatusCode.ExpectationFailed };
handler.HandleUpload(file.Name, file.Value);
return new Response { StatusCode = HttpStatusCode.Accepted };
});
}
}
}