使用ckeditor从用户本地路径上传文件? [英] Upload files from users local path using ckeditor?

查看:415
本文介绍了使用ckeditor从用户本地路径上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ckeditor和ckeditor的uploadimage插件,这些插件可帮助我在粘贴或放置在ckeditor上时上传图像.但是,当我从具有一些图像的单词中复制内容并将其粘贴到ckeditor上时,它没有上传该图像,因为它除了图像之外还有很多其他内容.现在粘贴后,我有了来自用户本地的图像路径.我可以使用ckeditor或通过javascript从用户的本地路径上传这些文件到我的服务器吗?

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这是我正在谈论的插件.

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

推荐答案

否. JavaScript无法访问您的本地驱动器. uploadimage处理它从浏览器获取的HTML,它取决于浏览器,操作系统,在这种情况下还取决于MS Word的版本. JavaScript从Clipboard API获取数据,并且如果将返回本地路径而不是真实数据,并且没有文件,则无法做任何明智的事情.

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.

但是请确保您可以检查dataTransfer包含的内容.可能不仅有HTML,而且还有可以上载的文件.添加粘贴侦听器:

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() );
} );

如果其中包含文件,则可以使用 fileLoader 上载它,完成上传后,将本地路径替换为服务器上图像的路径.

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.

这篇关于使用ckeditor从用户本地路径上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆