我为此苦了一天。我知道该线程以前经常被访问过,但是我无法弄清楚自己在做什么错。我将代码发布在这里,希望您能看看是否有问题。
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);
}
});