IO / HTTP error in Uploadify in asp.net mvc2
I am using uploadify tool to upload my files with out posting back and I开发者_JS百科 am facing this problem "IO Error" or "HTTP Error" after publishing the site.
This is my code sample :
$('#UploadFile').uploadify({
'uploader': '/Content/uploadify.swf',
'script': '/Home/uploadify',
'cancelImg': '/Content/cancel.png',
'folder': '/Content/UploadedFiles',
'auto': true
});
this is my action code
[HttpPost]
public string uploadify()
{
string fileDirectory = Server.MapPath(@"\Content\UploadedFiles\");
string signuterName = _fileStore.SaveUploadedFile(Request.Files[0], fileDirectory);
Session["SignuterfilePath"] = @"/Content/UploadedFiles/" + signuterName;
return signuterName;
}
http://www.uploadify.com/documentation/
thanks.
You seem to have hardcoded urls which might break when deploying your site under a virtual directory. I would recommend you always using URL helpers when dealing with urls:
$('#UploadFile').uploadify({
'uploader': '<%= Url.Content("~/Content/uploadify.swf") %>',
'script': '<%= Url.Action("Uploadify", "Home") %>',
'cancelImg': '<%= Url.Content("~/Content/cancel.png") %>',
'folder': '<%= Url.Content("~/Content/UploadedFiles") %>',
'auto': true
});
UPDATE:
Also your controller actions normally return ActionResults not strings:
[HttpPost]
public ActionResult Uploadify()
{
// Notice the argument of the MapPath method:
string fileDirectory = Server.MapPath(@"~/Content/UploadedFiles/");
string signuterName = _fileStore.SaveUploadedFile(Request.Files[0], fileDirectory);
// Warning: You don't have access to the Session in requests
// performed by Flash plugins
//Session["SignuterfilePath"] = @"/Content/UploadedFiles/" + signuterName;
// Return an ActionResult
return Content(signuterName, "text/plain");
}
You will also notice that I have removed the Session call from your controller action. The reason for this is the the Uploadify plugin uses Flash and Flash doesn't have access to cookies, so when the request is performed there won't be any Session associated with it.
精彩评论