我正在使用
https://github.com/blueimp/jQuery-File-Upload,我能够将文件上传并保存到指定的文件夹,然后我返回Json对象.然后浏览器(我使用IE8)弹出“文件下载”对话框,并要求我下载一个名为“upload75bea5a4”的文件,没有扩展名.我只是弄清楚出了什么问题?
解决方法
我正在使用相同的插件,它对我没有任何问题.我将发布我正在使用的代码,以便可以帮助您.我在
Scott Hanselman’s blog看到的C#代码(我做了一些改动).
- public class ViewDataUploadFilesResult
- {
- public string Name { get; set; }
- public int Length { get; set; }
- public string Type { get; set; }
- }
- [HttpPost]
- public string UploadFiles()
- {
- var r = new List<ViewDataUploadFilesResult>();
- Core.Settings settings = new Core.Settings();
- foreach (string file in Request.Files)
- {
- HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
- if (hpf.ContentLength == 0)
- continue;
- string savedFileName = Path.Combine(settings.StorageLocation + "\\Files\\",Path.GetFileName(hpf.FileName));
- hpf.SaveAs(savedFileName);
- r.Add(new ViewDataUploadFilesResult()
- {
- Name = hpf.FileName,Length = hpf.ContentLength,Type = hpf.ContentType
- });
- }
- return "{\"name\":\"" + r[0].Name + "\",\"type\":\"" + r[0].Type + "\",\"size\":\"" + string.Format("{0} bytes",r[0].Length) + "\"}";
- }
制作魔法的javascript片段:
- $('#file_upload').fileUploadUI({
- uploadTable: $('#files'),downloadTable: $('#files'),buildUploadRow: function (files,index) {
- return $('<tr><td>' + files[index].name + '<\/td>' +
- '<td class="file_upload_progress"><div><\/div><\/td>' +
- '<td class="file_upload_cancel">' +
- '<button class="ui-state-default ui-corner-all" title="Cancel">' +
- '<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
- '<\/button><\/td><\/tr>');
- },buildDownloadRow: function (file) {
- return $('<tr><td>' + file.name + '<\/td><\/tr>');
- }
- });
看看并做一些测试.
–
编辑