From ab4a29839756a0fc69b3a1b0739865a3b9e037fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Mon, 20 Apr 2020 13:52:39 +0200 Subject: [PATCH] Other: Remove the Edge-specific fallback for image upload. ckeditor/ckeditor5#6202. Agreed at https://github.com/ckeditor/ckeditor5-utils/pull/333#issuecomment-615275702 --- src/imageupload/utils.js | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/imageupload/utils.js b/src/imageupload/utils.js index e39ac3ef..22cc4386 100644 --- a/src/imageupload/utils.js +++ b/src/imageupload/utils.js @@ -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 ); } ); @@ -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; - } -}