Skip to content

Instantly share code, notes, and snippets.

@GuyHarwood
Last active December 12, 2015 05:28
Show Gist options
  • Save GuyHarwood/4722310 to your computer and use it in GitHub Desktop.
Save GuyHarwood/4722310 to your computer and use it in GitHub Desktop.
Accept form POST with file upload
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Upload(int id, IEnumerable<HttpPostedFileBase> files)
{
var results = new List<UploadResult>();
var uploads = new List<PhotoUpload>();
foreach (var file in files)
{
if (file.ContentLength > 0)
{
var p = new PhotoUpload()
{
AddedOn = DateTime.Now,
ContentType = "image/jpeg",
LocationId = id,
ImageStream = file.InputStream
};
uploads.Add(p);
results.Add(new UploadResult()
{
name = "upload complete",
size = file.ContentLength.ToString(),
thumbnail_url = @"/Content/Images/YellowTick.gif"
});
}
}
var saveLocation = Server.MapPath(_cfg.LocationImages);
_svc.Create(uploads, saveLocation);
return Json(results);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment