Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Other: Remove the Edge-specific fallback for image upload. ckeditor/c…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomalec committed Apr 20, 2020
1 parent 48a810d commit ab4a298
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/imageupload/utils.js
Expand Up @@ -44,9 +44,9 @@ export function fetchLocalImage( image ) {
const mimeType = getImageMimeType( blob, imageSrc );
const ext = mimeType.replace( 'image/', '' );
const filename = `image.${ ext }`;
const file = createFileFromBlob( blob, filename, mimeType );
const file = new File( [ blob ], filename, { type: mimeType } );

file ? resolve( file ) : reject();
resolve( file );
} )
.catch( reject );
} );
Expand Down Expand Up @@ -82,21 +82,3 @@ function getImageMimeType( blob, src ) {
return 'image/jpeg';
}
}

// Creates a `File` instance from the given `Blob` instance using the specified file name.
//
// @param {Blob} blob The `Blob` instance from which the file will be created.
// @param {String} filename The file name used during the file creation.
// @param {String} mimeType The file MIME type.
// @returns {File|null} The `File` instance created from the given blob or `null` if `File API` is not available.
function createFileFromBlob( blob, filename, mimeType ) {
try {
return new File( [ blob ], filename, { type: mimeType } );
} catch ( err ) {
// Edge does not support `File` constructor ATM, see https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9551546/.
// However, the `File` function is present (so cannot be checked with `!window.File` or `typeof File === 'function'`), but
// calling it with `new File( ... )` throws an error. This try-catch prevents that. Also when the function will
// be implemented correctly in Edge the code will start working without any changes (see #247).
return null;
}
}

0 comments on commit ab4a298

Please sign in to comment.