我创建上传简历的方法。它没有显示任何错误。当我打开文件时,它显示为空..没有数据..
我的控制器
[HandleErrorWithAjaxFilter]
public ActionResult UploadResume(HttpPostedFileBase FileData)
{
Stream fromStream = FileData.InputStream;
Stream toStream = new FileStream(Server.MapPath("~/Content/Resumes/") + FileData.FileName, FileMode.Create);
LoggedInCandidate.ResumeFileName = FileData.FileName;
//_repository.Save();
_userRepository.Save();
return Json(new JsonActionResult
{
Success = true,
Message = "Resume has been uploaded."
});
//return Json("Resume has been uploaded.");
}
查看:
<input id="Resume" type="file" name="Resume" />
Jquery的:
Models.Candidate.AddUploadResumeBehavior = function () {
$('#Resume').uploadify({
'swf': root + '/Content/Flash/uploadify.swf',
'uploader': root + '/Candidates/UploadResume',
'cancelImg': root + '/Content/Images/uploadify-cancel.png',
'auto': true,
'multi': true,
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg;*.doc',
'queueSizeLimit': 90,
'sizeLimit': 4000000,
'buttonText': 'Upload Resume',
'width': 200,
'folder': root + '/uploads',
'onComplete': function (event, queueID, fileObj, response, data) {
Models.Candidate.ShowMessageBar("Resume has been uploaded.");
},
'onError': function (event, ID, fileObj, errorObj) {
var msg;
if (errorObj.type === "File Size")
msg = 'File size cannot exceed 4MB';
else
msg = "An error occured while attempting to uploading resume."
Models.Candidate.ShowMessageBar(msg);
this.hide();
}
});
};
请找到问题并帮助我。
答案 0 :(得分:0)
您没有在代码中使用fromStream ...您只是创建一个新文件并关闭它。因此0字节长度。
在.Net 4中你可以这样做:
Stream fromStream = FileData.InputStream;
Stream toStream = new FileStream(Server.MapPath("~/Content/Resumes/") + FileData.FileName, FileMode.Create);
// Actually upload the bytes!
fromStream.CopyTo(toStream);