这是当前代码:JS:
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" }
};
}
}
如何制作一个进度条来表示服务器端的上传进度?我如何获得SaveAs
(如果可能的话)的上传进度,如果不是我必须改变什么?
提前致谢 !