I’m uploading images:
[HttpPost]
public ActionResult Create(PlaceViewModel model)
{
if (ModelState.IsValid)
{
string fileName = Guid.NewGuid().ToString() + ".jpg";
string serverPath = Server.MapPath("~");
string imagesPath = serverPath + "Content\\Uploads\\";
string thumbPath = imagesPath + "Thumb\\";
string fullPath = imagesPath + "Full\\";
ImageModel.ResizeAndSave(thumbPath, fileName, model.ImageUploaded.InputStream, 100, true);
ImageModel.ResizeAndSave(fullPath, fileName, model.ImageUploaded.InputStream, 600, true);
model.Image = fileName;
var place = new Place();
model.ConvertToData(place);
_placeRepository.Add(place);
_placeRepository.SaveChanges();
return RedirectToAction("Index");
}
return View(model);
}
File uploads and exist physical in disk
I’m calling image from html:
<img height="100px" src="/Content/Uploads/Thumb/833c4384-884d-4250-982c-d5df0fa875ef.jpg" width="100px"/>
But I don’t see this image.
If I call localhost:23354/Content/Uploads/Thumb/833c4384-884d-4250-982c-d5df0fa875ef.jpg I have error:
The resource cannot be found. Description: HTTP 404. The resource
you are looking for (or one of its dependencies) could have been
removed, had its name changed, or is temporarily unavailable. Please
review the following URL and make sure that it is spelled correctly.Requested URL:
/Content/Uploads/Thumb/833c4384-884d-4250-982c-d5df0fa875ef.jpg
what am I doing wrong?
I loosers.
images saved in
ImageModel.ResizeAndSaveand append name extension ‘.jpg’it turns out that the file is filename.jpg.jpeg