在我的應用程序中最近發生的更改之後,仍然在使用數據庫中的相對路徑顯示圖像時出現此問題。 Error: 404 NOT FOUND http://localhost:1256/Empdet/%22/Photos/jobs.jpg%22
從數據庫中顯示錯誤的圖像
Controller.js:
$scope.UploadFile = function() {
console.log('UploadFile');
console.log($scope.Empdet.PhotoFile);
var file = $scope.Empdet.PhotoFile;
console.log('file is ' + JSON.stringify(file));
var uploadUrl = "../Photos";
console.log('before file upload');
EmployeeFactory.UploadFile(file, uploadUrl).success(function (response) {
$scope.Empdet.PhotoText = response;
console.log('$scope.Empdet.PhotoText');
console.log(response);
}).error(function() {
console.log('error');
});
console.log('after file upload');
};
service.js:
service.UploadFile = function (file, uploadUrl) {
var fd = new FormData();
fd.append('file', file);
return $http.post('/Empdet/UploadFile', fd, {
transformRequest: angular.identity,
headers: { 'Content-Type': undefined }
});
}
EmpdetController.cs:
個[HttpPost]
public ActionResult UploadFile()
{
var file = Request.Files[0];
var path = Path.Combine(Server.MapPath("~/Photos/"), file.FileName);
file.SaveAs(path);
// prepare a relative path to be stored in the database and used to display later on.
var filename = Url.Content("~/Photos/" + file.FileName);
// save to db
return Json(filename.ToString(), JsonRequestBehavior.AllowGet);
}
嘗試刪除第二/從'」〜/ Photos /「'? –
@PrashantGhimire哪個會給你/ PhotosFileName?我不認爲這是答案..但我可能是錯的 – Billy
@Frankline我認爲你的URL中有一些額外的引號(「),瀏覽器轉換爲%22,如果這不是你的意圖,那就是你的問題。 – Billy