我正在尝试从服务器端的文件上传器获取整个路径..它在IE中工作..我在IE中获得了完整路径但是没有在chrome中可能是因为安全问题..请让我知道如果我在我的代码中犯了任何错误,如果它是正确的,那么建议我解决..
HTML
@using (Html.BeginForm("AppEditorHome", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" id="upload_file" style="display: none;" name="file" onchange="uploadedFileDetail()" />
}
JS
function uploadedFileDetail() {
var formdata = new FormData();
var fileInput = document.getElementById('upload_file');
var filename = fileInput.files[0].name;
formdata.append(fileInput.files[0].name, fileInput.files[0]);
var xhr = new XMLHttpRequest();
xhr.open('POST', '@Url.Action("uploadeFile", "Home")');
xhr.send(formdata);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) { debugger; }
}
}
控制器
public ActionResult uploadeFile() { return View(); }
[HttpPost]
public ActionResult uploadeFile(HttpPostedFileBase file)
{
try
{
int count = Request.Files.Count;
if (count == 1)
{
file = Request.Files[0];
var clientPath = Path.GetDirectoryName(file.FileName);
var fileName = Path.GetFileName(file.FileName);
var path = Path.GetFullPath(file.FileName);
var data = new
{
uploaded = Request.Files
};
return Json(data);
}
return Json("");
}
catch (Exception ex) { return Json(""); }
}
}