Last active
December 12, 2015 05:28
-
-
Save GuyHarwood/4722310 to your computer and use it in GitHub Desktop.
Accept form POST with file upload
This file contains 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
[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