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

Commit

Permalink
Allow per-file chunk sizes to be specified.
Browse files Browse the repository at this point in the history
chunking.partSize now accepts a function, which passes the file ID and size
closes #1697
  • Loading branch information
rnicholus committed Oct 14, 2017
1 parent e72a779 commit 8eb98d7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions client/js/upload-handler/upload.handler.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ qq.UploadHandlerController = function(o, namespace) {
log("Problem finalizing chunks for file ID " + id + " - " + normalizedResponse.error, "error");

if (
normalizedResponse.reset
|| (xhr && options.chunking.success.resetOnStatus.indexOf(xhr.status) >= 0)
normalizedResponse.reset ||
(xhr && options.chunking.success.resetOnStatus.indexOf(xhr.status) >= 0)
) {
chunked.reset(id);
}
Expand Down
28 changes: 23 additions & 5 deletions client/js/upload-handler/xhr.upload.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ qq.XhrUploadHandler = function(spec) {
namespace = spec.options.namespace,
proxy = spec.proxy,
chunking = spec.options.chunking,
getChunkSize = function(id) {
var fileState = handler._getFileState(id);

if (fileState.chunkSize) {
return fileState.chunkSize;
}

else {
var chunkSize = chunking.partSize;

if (qq.isFunction(chunkSize)) {
chunkSize = chunkSize(id, getSize(id));
}

fileState.chunkSize = chunkSize;
return chunkSize;
}
},
resume = spec.options.resume,
chunkFiles = chunking && spec.options.chunking.enabled && qq.supportedFeatures.chunking,
resumeEnabled = resume && spec.options.resume.enabled && chunkFiles && qq.supportedFeatures.resume,
Expand Down Expand Up @@ -141,8 +159,8 @@ qq.XhrUploadHandler = function(spec) {
},

isResumable: function(id) {
return !!chunking && handler.isValid(id)
&& !handler._getFileState(id).notResumable;
return !!chunking && handler.isValid(id) &&
!handler._getFileState(id).notResumable;
},

moveInProgressToRemaining: function(id, optInProgress, optRemaining) {
Expand Down Expand Up @@ -232,7 +250,7 @@ qq.XhrUploadHandler = function(spec) {
},

_getChunkData: function(id, chunkIndex) {
var chunkSize = chunking.partSize,
var chunkSize = getChunkSize(id),
fileSize = getSize(id),
fileOrBlob = handler.getFile(id),
startBytes = chunkSize * chunkIndex,
Expand Down Expand Up @@ -273,7 +291,7 @@ qq.XhrUploadHandler = function(spec) {
var formatVersion = "5.0",
name = getName(id),
size = getSize(id),
chunkSize = chunking.partSize,
chunkSize = getChunkSize(id),
endpoint = getEndpoint(id),
customKeys = resume.customKeys(id),
localStorageId = qq.format("qq{}resume{}-{}-{}-{}-{}", namespace, formatVersion, name, size, chunkSize, endpoint);
Expand All @@ -300,7 +318,7 @@ qq.XhrUploadHandler = function(spec) {
_getTotalChunks: function(id) {
if (chunking) {
var fileSize = getSize(id),
chunkSize = chunking.partSize;
chunkSize = getChunkSize(id);

return Math.ceil(fileSize / chunkSize);
}
Expand Down
4 changes: 3 additions & 1 deletion client/js/uploader.basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@
totalFileSize: "qqtotalfilesize",
totalParts: "qqtotalparts"
},
partSize: 2000000,
partSize: function(id) {
return 2000000;
},
// only relevant for traditional endpoints, only required when concurrent.enabled === true
success: {
endpoint: null,
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.16.0-alpha.11";
qq.version = "5.16.0-alpha.12";
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.16.0-alpha.11",
"version": "5.16.0-alpha.12",
"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

0 comments on commit 8eb98d7

Please sign in to comment.