From: Mark Holmquist Date: Tue, 2 Feb 2016 17:00:28 +0000 (-0600) Subject: Add Blob to accepted types for uploads X-Git-Tag: 1.31.0-rc.0~8107^2 X-Git-Url: http://git.cyclocoop.org/%22.%20%20%20generer_url_action%28%22logout%22%2C%22logout=prive%22%29%20.%20%20%20%22?a=commitdiff_plain;h=7b5194988e81419f9d9ed6ea0222d43b58edf7d6;p=lhc%2Fweb%2Fwiklou.git Add Blob to accepted types for uploads From https://developer.mozilla.org/en-US/docs/Web/API/File : A File object is specific kind of a Blob, and can be used in any context that a Blob can. In particular, FileReader, URL.createObjectURL(), createImageBitmap(), and XMLHttpRequest.send() accept both Blobs and Files. Change-Id: I171f884fc4ada6180e5c605a44b27044fc03f26e --- diff --git a/jsduck.json b/jsduck.json index aac76c57b1..53300c56e4 100644 --- a/jsduck.json +++ b/jsduck.json @@ -7,7 +7,7 @@ "--builtin-classes": true, "--processes": "0", "--warnings-exit-nonzero": true, - "--external": "HTMLElement,HTMLDocument,Window,File,MouseEvent,KeyboardEvent,HTMLIframeElement,HTMLInputElement,XMLDocument", + "--external": "HTMLElement,HTMLDocument,Window,Blob,File,MouseEvent,KeyboardEvent,HTMLIframeElement,HTMLInputElement,XMLDocument", "--output": "docs/js", "--": [ "maintenance/jsduck/external.js", diff --git a/resources/src/mediawiki/api/upload.js b/resources/src/mediawiki/api/upload.js index 303623755b..47d80d690e 100644 --- a/resources/src/mediawiki/api/upload.js +++ b/resources/src/mediawiki/api/upload.js @@ -116,7 +116,7 @@ * - It is incompatible with uploads to a foreign wiki using mw.ForeignApi * - You must pass a HTMLInputElement and not a File for it to be possible * - * @param {HTMLInputElement|File} file HTML input type=file element with a file already inside + * @param {HTMLInputElement|File|Blob} file HTML input type=file element with a file already inside * of it, or a File object. * @param {Object} data Other upload options, see action=upload API docs for more * @return {jQuery.Promise} @@ -134,7 +134,8 @@ throw new Error( 'No file' ); } - canUseFormData = formDataAvailable() && file instanceof window.File; + // Blobs are allowed in formdata uploads, it turns out + canUseFormData = formDataAvailable() && ( file instanceof window.File || file instanceof window.Blob ); if ( !isFileInput && !canUseFormData ) { throw new Error( 'Unsupported argument type passed to mw.Api.upload' ); diff --git a/resources/src/mediawiki/mediawiki.Upload.js b/resources/src/mediawiki/mediawiki.Upload.js index 8a74ffc6ab..c972f24538 100644 --- a/resources/src/mediawiki/mediawiki.Upload.js +++ b/resources/src/mediawiki/mediawiki.Upload.js @@ -114,7 +114,7 @@ /** * Set the file to be uploaded. * - * @param {HTMLInputElement|File} file + * @param {HTMLInputElement|File|Blob} file */ UP.setFile = function ( file ) { this.file = file; @@ -159,7 +159,7 @@ /** * Get the file being uploaded. * - * @return {HTMLInputElement|File} + * @return {HTMLInputElement|File|Blob} */ UP.getFile = function () { return this.file;