現在のコードは次のとおりです: 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
ばよいですか? そうでない場合は、何を変更する必要がありますか?
前もって感謝します !