我上傳圖片:爲什麼不找一個資源
[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);
}
文件上傳和在磁盤上存在物理
我從HTML調用圖像:
<img height="100px" src="/Content/Uploads/Thumb/833c4384-884d-4250-982c-d5df0fa875ef.jpg" width="100px"/>
但我不看不到這張圖片。
如果我打電話localhost:23354/Content/Uploads/Thumb/833c4384-884d-4250-982c-d5df0fa875ef.jpg
我有錯誤:
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
我究竟做錯了什麼?
是在您的網址的根內容?您正在請求/內容中的圖片,但是當您上傳圖片時,您已將其上傳到〜/ content/...他們是否是同一位置? – Brettski
爲什麼在這個問題上有兩個反對票? – Brettski
我同意Brettski。這是一個完全有效的問題。從我+1。 –