gpt4 book ai didi

jquery-plugins - jQuery 文件上传插件要求我下载文件,有什么问题吗?

转载 作者:行者123 更新时间:2023-12-04 06:46:28 27 4
gpt4 key购买 nike

我正在使用 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; }
}

ajax调用的上传代码:

    [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>');
}
});

看一看并做一些测试。

--

编辑

I wrote an article about it .

关于jquery-plugins - jQuery 文件上传插件要求我下载文件,有什么问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5086189/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com