ソースを参照

Other: Remove the Edge-specific fallback for image upload. ckeditor/ckeditor5#6202.

Agreed at https://github.com/ckeditor/ckeditor5-utils/pull/333#issuecomment-615275702
Tomek Wytrębowicz 5 年 前
コミット
48f219266a
1 ファイル変更2 行追加20 行削除
  1. 2 20
      packages/ckeditor5-image/src/imageupload/utils.js

+ 2 - 20
packages/ckeditor5-image/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;
-	}
-}