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

Commit

Permalink
feat(uploader.basic.api.js): removeFileRef method (#1737)
Browse files Browse the repository at this point in the history
When called, this deleted the reference to the Blob/File (along with all other file state tracked by the upload handler).
closes #1711

* docs(methods.jmd): document removeFileRef method
closes #1711
  • Loading branch information
rnicholus authored Jan 30, 2017
1 parent 503d7e1 commit ad5bffc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions client/js/uploader.basic.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@
return false;
},

removeFileRef: function(id) {
this._handler.expunge(id);
},

reset: function() {
this.log("Resetting uploader...");

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.12.0";
qq.version = "5.14.0-beta1";
14 changes: 14 additions & 0 deletions docs/api/methods.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ $(document).ready(function() {
{% markdown %}
## Core
{% endmarkdown %}

{{
alert("If you pass a large `Blob` that was created using JavaScript in the browser into `addFiles`, you should consider calling the [`removeFileRef` method](#removeFileRef) after the file has been successfully uploaded to free up any memory consumed by the Blob.")
}}

{{ api_method("addFiles", "addFiles (files[, params[, endpoint]])", "Submit one or more files to the uploader.

A `BlobWrapper` object:
Expand Down Expand Up @@ -352,6 +357,15 @@ A `resizeInfo` object, which will be passed to the supplied function, contains t

]) }}

{{ api_method("removeFileRef", "removeFileRef (id)", "",
[
{
"name": "id",
"type": "Integer",
"description": "Remove internal reference to the associated Blob/File object. For Blobs that are created via JavaScript in the browser, this will free up all consumed memory."
}
]) }}

{{ api_method("reset", "reset ()", "Reset Fine Uploader", null, null) }}

{{ api_method("retry", "retry (id)", "Attempt to upload a specific item again.",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fine-uploader",
"title": "Fine Uploader",
"main": "lib/traditional.js",
"version": "5.13.0",
"version": "5.14.0-beta1",
"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
25 changes: 25 additions & 0 deletions test/unit/simple-file-uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,5 +478,30 @@ if (qqtest.canDownloadFileAsBlob) {
uploader.addFiles(canvasWrapper);
});
});

it("removes reference to a Blob via API", function(done) {
qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function(blob) {
fileTestHelper.mockXhr();

var request,
uploader = new qq.FineUploaderBasic({
autoUpload: false,
request: { endpoint: testUploadEndpoint },
callbacks: {
onComplete: function(id) {
assert.ok(uploader.getFile(id));
uploader.removeFileRef(id);
assert.ok(!uploader.getFile(id));
done();
}
}
});

uploader.addFiles({name: "test", blob: blob});
uploader.uploadStoredFiles();

fileTestHelper.getRequests()[0].respond(200, null, JSON.stringify({success: true}));
});
});
});
}

0 comments on commit ad5bffc

Please sign in to comment.