Add Blob to accepted types for uploads
authorMark Holmquist <mtraceur@member.fsf.org>
Tue, 2 Feb 2016 17:00:28 +0000 (11:00 -0600)
committerBartosz Dziewoński <matma.rex@gmail.com>
Tue, 2 Feb 2016 20:09:22 +0000 (21:09 +0100)
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

jsduck.json
resources/src/mediawiki/api/upload.js
resources/src/mediawiki/mediawiki.Upload.js

index aac76c5..53300c5 100644 (file)
@@ -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",
index 3036237..47d80d6 100644 (file)
                 * - 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}
                                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' );
index 8a74ffc..c972f24 100644 (file)
        /**
         * Set the file to be uploaded.
         *
-        * @param {HTMLInputElement|File} file
+        * @param {HTMLInputElement|File|Blob} file
         */
        UP.setFile = function ( file ) {
                this.file = file;
        /**
         * Get the file being uploaded.
         *
-        * @return {HTMLInputElement|File}
+        * @return {HTMLInputElement|File|Blob}
         */
        UP.getFile = function () {
                return this.file;