ASP.Net 코어에 파일 업로드를 쓰고 있는데 진행률 막대를 업데이트하려고하지만 진행 작업이 자바 스크립트에서 호출되면 세션 값이 업데이트되지 않습니다. 정확히.ASP.Net 코어 파일 업로드 진행 세션
public static void StoreInt(ISession session, string key, int value)
{
session.SetInt32(key, value);
}
업로드 :
intervalId = setInterval(
function() {
$.post(
"/Upload/Progress",
function (progress) {
$(".progress-bar").css("width", progress + "%").attr("aria-valuenow", progress);
$(".progress-bar").html(progress + "%");
}
);
},
1000
);
업로드 작업 :
,532$.ajax(
{
url: "/Upload",
data: formData,
processData: false,
contentType: false,
type: "POST",
success: function (data) {
clearInterval(intervalId);
$("#progress").hide();
$("#upload-status").show();
}
}
);
가 진행 값을 얻기
진행을 사용하여 사용자 세션에 저장됩니다 10
진행 작업 :
$.ajax(
{
url: "/Upload",
data: formData,
processData: false,
contentType: false,
type: "POST",
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var progress = Math.round((evt.loaded/evt.total) * 100);
$(".progress-bar").css("width", progress + "%").attr("aria-valuenow", progress);
$(".progress-bar").html(progress + "%");
}
}, false);
return xhr;
},
success: function (data) {
$("#progress").hide();
$("#upload-status").show();
}
}
);
여러분의 도움에 감사드립니다 :
[HttpPost]
public ActionResult Progress()
{
int progress = GetProgress(HttpContext.Session);
// GetProgress doesn't return the correct value: 0 when uploading the first file, a random value (0-100) when uploading any other file
return Content(progress.ToString());
}
로컬로 테스트하나요? 업로드 한 파일의 길이는 얼마입니까? –
로컬 및 원격 서버에서 모두 시도했지만 실패했습니다. 나 또한 하나의/여러 작은/큰 파일 (들)와 함께 노력했다. 여기에서 문제를 재현 할 수있는 솔루션을 만들었습니다. https://github.com/Fxbouffant/FileUploadCore 진행 작업은 파일을 업로드하는 동안 항상 0을 반환합니다. 그런 다음 파일을 업로드 할 때 100을 반환하고 그 사이에는 아무 값도 반환하지 않습니다. – GlobalFx
진행을 확인하는 간격은 1 초입니다. 프로세스를 확인하기 전에 다운로드를 종료 할 수 있습니까? –