I'm hoping someone can modify my code below to show me exactly how to get this to do what I want.
I have an HTML form that posts to the following action:
public ActionResult Create(string EntryTitle, string EntryVideo, HttpPostedFileBase ImageFile, string EntryDesc)
{
if (Session["User"] != null)
{
User currentUser = (User)Session["User"];
string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(ImageFile.FileName));
ImageFile.SaveAs(savedFileName);
Entry newEntry = new Entry();
newEntry.Title = EntryTitle;
newEntry.EmbedURL = EntryVideo;
newEntry.Description = EntryDesc;
newEntry.ImagePath = savedFileName;
newEntry.UserId = currentUser.UserId;
db.Entries.Add(newEntry);
db.SaveChanges();
}
return RedirectToAction("MyPage", "User");
}
This saves the image to the root solution directory (or tries to, doesn't have permission and throws exception instead).
What I would like it to do is the following:
1.) Verify that the file size is under some maximum, let's say 500kb for now
2.) Assuming file size is okay, save it to the following directory
mywebsite.com/uploads/<userid>/<entryid>/entry-image.<jpg/png/gif>
I'm not sure how to rename the file since I want to accept different file extensions (.jpeg, .jpg, .png, .gif). Or unsure how to get it into the correct directory like above. Or how to validate file size, since apparently you can only do that with javascript if the user is using IE.