Last active
November 2, 2016 00:16
-
-
Save jussimattila/e4378b1cdf4837fb5323 to your computer and use it in GitHub Desktop.
File upload with NancyFX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace NancyUpload | |
{ | |
using System; | |
using System.IO; | |
using System.Linq; | |
using Nancy; | |
public class UploadModule : NancyModule | |
{ | |
public UploadModule(): base() | |
{ | |
Post["upload"] = _ => | |
{ | |
var file = Request.Files.Single(); | |
var fullName = Path.Combine( | |
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), file.Name); | |
using (var fileStream = File.OpenWrite(fullName)) | |
{ | |
file.Value.CopyTo(fileStream); | |
} | |
return HttpStatusCode.OK; | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment