Ajax FileUpload & JQuery formData в ASP. NET MVC не работает - PullRequest
0 голосов
/ 11 февраля 2020

Я борюсь с этим уже один день. Я знаю, что к этой теме часто обращались раньше, но я не могу понять, что я делаю неправильно. Я опубликую код здесь, и я надеюсь, что вы можете увидеть, если это что-то не так.

var chunk = new File([fileChunks[currentPart - 1]], fileName);

    if (window.FormData !== undefined) {
        var formData = new FormData();
        formData.append('file', chunk, fileName);
        formData.append("fileName", fileName);
        }

    //var blobFile = blobToFile(fileChunks[currentPart - 1], fileName, testFile.type)


    $.ajax({
        type: "POST",
        url: my.static.uploadLargeFileUrl,
        async: true,
        cache: false,
        contentType: false,
        processData: false,
        dataType: 'json',
        data: formData,
        success: function (response) {
            console.log('uploading file part ' + currentPart + "out of " + totalPart)
            if (response.status == true) {
                if (currentPart == totalPart) { console.log('whole file uploaded'); }
                else { uploadFileChunk(fileChunks, fileName, currentPart + 1, totalPart); }
            }
            else {
                console.log('failed to upload part' + currentPart);
            }
        },
        error: function () {
        //retry message to upload rest of the file
            console.log("error to upload file part no: " + currentPart);
            uploadFileChunk(fileChunks, fileName, currentPart, totalPart);
    }

    });
...