Skip to content

Instantly share code, notes, and snippets.

@jussimattila
Last active November 2, 2016 00:16
Show Gist options
  • Save jussimattila/e4378b1cdf4837fb5323 to your computer and use it in GitHub Desktop.
Save jussimattila/e4378b1cdf4837fb5323 to your computer and use it in GitHub Desktop.
File upload with NancyFX
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