CKEDITOR.fileTools.fileLoader

需求:将网络上的图片可以自动保存到本地服务器上,也得出的结论还是在服务端做操作比较好。除非自己将图片下载下来转成blob格式或者base64。

http://docs.ckeditor.com/#!/api/CKEDITOR.fileTools.fileLoader

ckeditor提供的实例只支持Blob跟base64时才有用。

There are two possible ways to crate a FileLoader instance: with a Blob (e.g. got from the CKEDITOR.plugins.clipboard.dataTransfer.getFile method) or with a data as a Base64 string. Note that if the constructor gets the data as a Base64 string there is no need to load data, they are already loaded.
下面的源码会在evt.data.dataTransfer.getFilesCount()出错,console.log(evt)输出就知道了,连dataTransfer都不存在。
editor.on( 'paste', function( evt ) {
    for ( var i = 0; i < evt.data.dataTransfer.getFilesCount(); i++ ) {
        var file = evt.data.dataTransfer.getFile( i );

        if ( CKEDITOR.fileTools.isTypeSupported( file, /image\/png/ ) ) {
            var loader = editor.uploadsRepository.create( file );

            loader.on( 'update', function() {
                document.getElementById( 'uploadProgress' ).innerHTML = loader.status;
            } );

            loader.on( 'error', function() {
                alert( 'Error!' );
            } );

            loader.loadAndUpload( 'http://upload.url/' );

            evt.data.dataValue += 'loading...'
        }
    }
} );


猜你喜欢

转载自blog.csdn.net/ozhangsangong/article/details/45970337