0
下面是當前的代碼: JS:如何使用ASP.net C#和ExtJS 4製作上傳進度條?
var files = new Array();
function() {
var me = this;
for (var i = 0; i < files.length; i++) {
var formData = new FormData();
formData.append('files', files[i]);
formData.append('folderId', (Ext.ComponentQuery.query('#treePanel')[0]).getSelectionModel().getSelection()[0].data.id);
var xhr = new XMLHttpRequest();
xhr.open('post', '/File/Upload', true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
me.getUserSessionStore().load();
me.getFilesStore().load();
}
};
xhr.send(formData);
}
}
和C#:
[Authorize]
[HttpPost]
public ActionResult Upload(HttpPostedFileBase files, long folderId)
{
var user = new UsersModel().GetUserByEmail(User.Identity.Name);
if (files != null)
{
string x = Path.GetExtension(files.FileName);
if (new FilesModel().GetFileTypes().ToList().Where(a => a.ftp_extension == x.TrimStart('.')).Count() != 0)
{
var dbPath = new FilesModel().GetPaths().First();
var fileName = Path.GetFileNameWithoutExtension(files.FileName);
var fileType = new FilesModel().GetFileTypes().ToList().First(a => a.ftp_extension == x.TrimStart('.'));
Directory.CreateDirectory(Server.MapPath("/Temp/") + user.usr_id);
var path = Path.Combine(Server.MapPath("/Temp/") + user.usr_id + "/", fileName);
files.SaveAs(path);
Directory.CreateDirectory(dbPath.pth_path + "/tmp/" + user.usr_id + "/");
if (System.IO.File.Exists(Server.MapPath("/Temp/" + user.usr_id + "/" + fileName)))
System.IO.File.Move(Server.MapPath("/Temp/" + user.usr_id + "/" + fileName), dbPath.pth_path + "tmp/" + user.usr_id + "/" + fileName);
var fileId = new FilesModel().CreateFile(user.usr_id, fileName, false, "", fileName, 1, fileType.ftp_id, user.usr_id, folderId);
if (System.IO.File.Exists(dbPath.pth_path + "tmp/" + user.usr_id + "/" + fileName))
System.IO.File.Move(dbPath.pth_path + "tmp/" + user.usr_id + "/" + fileName, dbPath.pth_path + new Pass().getMd5Hash(fileId.ToString()));
return Content("{success:true, result:\"File uploaded correctly\"}");
}
else
{
return Content("{success:false, error:\"Unsupported file type\"}");
}
}
return new JsonResult()
{
ContentType = "text/html",
Data = new { success = false, error = "File uploaded error" }
};
}
}
我怎麼能作出這樣的reprents在服務器端上傳進展的進度條?我如何獲得SaveAs
的上傳進度(如果可能的話),以及如果這不是我必須更改的內容?
在此先感謝!
在這裏有幾個樣本在SO ..你從哪裏得到你發佈的代碼? – lboshuizen
這是我的代碼。是的,我讀了一些線程,但沒有找到我的問題的答案。 – Elfayer
你必須改變什麼?很多!我看到很多控制器操作上傳一個文件,但他的一個... – lboshuizen