Search code examples
javascriptbrowserckeditorbrowser-security

Upload files from users local path using ckeditor?


I am using ckeditor and uploadimage plugin of ckeditor which help me in uploading an image when pasted or dropped on ckeditor. But when I am copying content from word which has some image and paste it on ckeditor it's not uploading that image because it has lot of other stuff other than image. Now After paste I have the path of the image from user's local. Can I upload those files from user's local path using ckeditor or through javascript to my server.?

http://docs.ckeditor.com/#!/guide/dev_file_upload this is the plugin I am talking about.


Solution

  • No. JavaScript has no access to you local drive. uploadimage handle HTML it gets from the browsers and it depends on browser, operation system and, in this case, the version of MS Word. JavaScript get data from the Clipboard API and if local path will be returned instead of real data, and no files, nothing smart can be done.

    But to be sure you can check what dataTransfer contains. It may happen that there is not only HTML but also file you can upload. Add the paste listener:

    editor.on( 'paste', function( evt ) {
        console.log( evt.data.dataTransfer.getData( 'text/html' ) );
        console.log( evt.data.dataTransfer.getFilesCount() );
    } );
    

    If it contains files you can upload it using fileLoader and, when upload is done, replace the local path with the path to the image on the server.