简体   繁体   English

使用ckeditor从用户本地路径上传文件?

[英]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.我正在使用 ckeditor 的 ckeditor 和 uploadimage 插件,它们可以帮助我在粘贴或放置在 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.但是当我从 word 中复制包含一些图像的内容并将其粘贴到 ckeditor 时,它不会上传该图像,因为它除了图像之外还有很多其他内容。 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.?我可以使用 ckeditor 或通过 javascript 将这些文件从用户的本地路径上传到我的服务器吗?

http://docs.ckeditor.com/#!/guide/dev_file_upload this is the plugin I am talking about. http://docs.ckeditor.com/#!/guide/dev_file_upload这是我正在谈论的插件。

No. JavaScript has no access to you local drive.不可以。JavaScript 无法访问您的本地驱动器。 uploadimage handle HTML it gets from the browsers and it depends on browser, operation system and, in this case, the version of MS Word. uploadimage处理它从浏览器获取的 HTML,它取决于浏览器、操作系统,在这种情况下,还取决于 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. JavaScript 从剪贴板 API 获取数据,如果将返回本地路径而不是真实数据,并且没有文件,则无法完成任何智能操作。

But to be sure you can check what dataTransfer contains.但可以肯定的是,您可以检查dataTransfer包含的内容。 It may happen that there is not only HTML but also file you can upload.可能会发生不仅有 HTML 还可以上传的文件。 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.如果它包含文件,您可以使用fileLoader上传它,上传完成后,将本地路径替换为服务器上图像的路径。

As Piotr said, Javascript can't read directly a local file or that would be a huge security problem.正如 Piotr 所说,Javascript 不能直接读取本地文件,否则这将是一个巨大的安全问题。

The best workaround that I'm aware about pasting images from MS Word is to use the Images From Word plugin that detects those images and prompts the user to upload them by just copying and pasting.我所知道的关于从 MS Word 粘贴图像的最佳解决方法是使用图像来自 Word插件来检测这些图像并提示用户通过复制和粘贴来上传它们。

It might not be important to you, but another good thing is that it doesn't require you to change the version of CKEditor as it works with any CKEditor 4.x这对您来说可能并不重要,但另一个好处是它不需要您更改 CKEditor 的版本,因为它适用于任何 CKEditor 4.x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM