Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Fix for https://github.com/FineUploader/fine-uploader/issues/1172 #1964

Merged
merged 4 commits into from
Jan 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client/js/uploader.basic.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@
self._options.callbacks.onUploadChunk(id, name, chunkData);
},
onUploadChunkSuccess: function(id, chunkData, result, xhr) {
self._onUploadChunkSuccess(id, chunkData);
self._options.callbacks.onUploadChunkSuccess.apply(self, arguments);
},
onResume: function(id, name, chunkData) {
Expand Down Expand Up @@ -1574,6 +1575,12 @@
//nothing to do in the base uploader
},

_onUploadChunkSuccess: function(id, chunkData) {
if (!this._preventRetries[id] && this._options.retry.enableAuto) {
this._autoRetries[id] = 0;
}
},

_onUploadStatusChange: function(id, oldStatus, newStatus) {
// Make sure a "queued" retry attempt is canceled if the upload has been paused
if (newStatus === qq.status.PAUSED) {
Expand Down
2 changes: 1 addition & 1 deletion client/js/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/*global qq */
qq.version = "5.15.5";
qq.version = "5.15.6";
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "Fine Uploader",
"main": "lib/traditional.js",
"types" : "typescript/fine-uploader.d.ts",
"version": "5.15.5",
"version": "5.15.6",
"description": "Multiple file upload plugin with progress-bar, drag-and-drop, direct-to-S3 & Azure uploading, client-side image scaling, preview generation, form support, chunking, auto-resume, and tons of other features.",
"keywords": [
"amazon",
Expand Down
88 changes: 88 additions & 0 deletions test/unit/chunked-uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ if (qqtest.canDownloadFileAsBlob) {
request.respond(200, null, JSON.stringify({success: true, testParam: "testVal"}));
}, 10);
},
onAutoRetry: function(id, name, attemptNumber) {
assert.fail("This should not be called");
},
onUploadChunkSuccess: function (id, chunkData, response, xhr) {
var request = fileTestHelper.getRequests()[fileTestHelper.getRequests().length - 1],
requestParams;
Expand Down Expand Up @@ -197,6 +200,87 @@ if (qqtest.canDownloadFileAsBlob) {
});
}

function testChunkedEveryFailureAndRecovery(done) {
var alreadyFailed = false,
uploader = new qq.FineUploaderBasic({
request: {
endpoint: testUploadEndpoint
},
chunking: {
enabled: true,
partSize: chunkSize
},
retry: {
autoAttemptDelay: 0,
enableAuto: true
},
callbacks: {
onUploadChunk: function (id, name, chunkData) {
chunksSent++;

assert.equal(id, 0, "Wrong ID passed to onUpoadChunk");
assert.equal(name, uploader.getName(id), "Wrong name passed to onUploadChunk");
assert.equal(chunkData.partIndex, chunksSent - 1, "Wrong partIndex passed to onUploadChunk");
assert.equal(chunkData.startByte, (chunksSent - 1) * chunkSize + 1, "Wrong startByte passed to onUploadChunk");
assert.equal(chunkData.endByte, chunksSent === expectedChunks ? expectedFileSize : chunkData.startByte + chunkSize - 1, "Wrong startByte passed to onUploadChunk");
assert.equal(chunkData.totalParts, expectedChunks, "Wrong totalParts passed to onUploadChunk");

setTimeout(function () {
var request = fileTestHelper.getRequests()[fileTestHelper.getRequests().length - 1];

if (!alreadyFailed) {
alreadyFailed = true;

chunksSent--;
request.respond(500, null, JSON.stringify({testParam: "testVal"}));
}
else {
alreadyFailed = false;
request.respond(200, null, JSON.stringify({success: true, testParam: "testVal"}));
}
}, 10);
},
onAutoRetry: function(id, name, attemptNumber) {
assert.equal(id, 0, "Wrong ID passed to onAutoRetry");
assert.equal(name, uploader.getName(id), "Wrong name passed to onAutoRetry");
assert.equal(attemptNumber, 1, "Wrong auto retry attempt #");
},
onUploadChunkSuccess: function (id, chunkData, response, xhr) {
var request = fileTestHelper.getRequests()[fileTestHelper.getRequests().length - 1],
requestParams = request.requestBody.fields;

chunksSucceeded++;

assert.equal(requestParams.qquuid, uploader.getUuid(id), "Wrong uuid param");
assert.equal(requestParams.qqpartindex, chunksSent - 1, "Wrong part index param");
assert.equal(requestParams.qqpartbyteoffset, (chunksSent - 1) * chunkSize, "Wrong part byte offset param");
assert.equal(requestParams.qqtotalfilesize, expectedFileSize, "Wrong total file size param");
assert.equal(requestParams.qqtotalparts, expectedChunks, "Wrong total parts param");
assert.equal(requestParams.qqfilename, uploader.getName(id), "Wrong filename param");
assert.equal(requestParams.qqchunksize, requestParams.qqfile.size, "Wrong chunk size param");
assert.equal(id, 0, "Wrong ID passed to onUpoadChunkSuccess");

assert.equal(response.testParam, "testVal");
},
onComplete: function (id, name, response) {
assert.equal(expectedChunks, chunksSent, "Wrong # of chunks sent.");
assert.equal(expectedChunks, chunksSucceeded, "Wrong # of chunks succeeded");
assert.equal(response.testParam, "testVal");
assert.equal(response.success, true);

done();
}
}
}),
chunksSent = 0,
chunksSucceeded = 0;

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addFiles({name: "test", blob: blob});
});
}

it("sends proper number of chunks when chunking is enabled, MPE", function(done) {
testChunkedUpload({
mpe: true,
Expand Down Expand Up @@ -246,6 +330,10 @@ if (qqtest.canDownloadFileAsBlob) {
testChunkedFailureAndRecovery(true, done);
});

it("fails every chunk once, then recovers and ensure attemptNumber is 1", function(done) {
testChunkedEveryFailureAndRecovery(done);
});

describe("resume feature tests", function() {
var nativeLocalStorageSetItem = window.localStorage.setItem,
acknowledgeRequests = function(endpoint) {
Expand Down