简体   繁体   English

在CKEditor上自动上传图像

[英]Automate image upload on CKEditor

I need to upload images on a website that uses CKEditor. 我需要在使用CKEditor的网站上上传图像。 For each image, I click "image" button -> "upload" tab -> " Choose file " button -> select file in file-browser -> "Send to server" button -> Wait for upload -> "Ok" button 对于每个图像,我单击“图像”按钮->“上传”标签->“ 选择文件 ”按钮->在文件浏览器中选择文件->“发送到服务器”按钮->等待上传->“确定”按钮

I am almost able to trigger appropriate "clicks" by entering javascript code in console except for the bolded step, ie, I am not able to trigger " Choose file " button on CKEditor, ie, I am not able to programmatically click the "Browse" button. 除了加粗的步骤外,我几乎可以通过在控制台中输入javascript代码来触发相应的“点击”,即,我无法在CKEditor上触发“ 选择文件 ”按钮,即,我无法以编程方式单击“浏览” ”按钮。 Note that once file-browser opens up, (by manual click), I can use autohotkey to enter address of my file followed by 'enter'. 请注意,一旦打开文件浏览器(通过手动单击),我可以使用自动快捷键输入文件地址,然后输入“ enter”。 Alternatively, I am not able to set the image upload path using javascript (skipping file-open dialog), which is a security risk, but I need to bypass it, at least by using my own addon/extension. 或者,我无法使用javascript(跳过文件打开对话框)设置图像上传路径,这存在安全隐患,但我至少需要使用自己的插件/扩展名来绕过它。 Please help me trigger the file browser or set image path directly into input. 请帮助我触发文件浏览器或将图像路径直接设置为输入。

Here is a demo of CKEditor: http://ckeditor.com/demo 这是CKEditor的演示: http : //ckeditor.com/demo

I could make following so far. 到目前为止,我可以关注。

//click image button
document.getElementsByClassName("cke_button__image")[0].click();

// click "upload" tab
document.getElementsByClassName("cke_dialog_tab")[2].click();

//Need to either trigger "choose file" dialog box or otherwise assign "C:\temp.png" to input

//Click "send to server" button
document.getElementsByClassName("cke_dialog_ui_button")[4].click();

//Need to wait, and then click "OK" button
document.getElementsByClassName("cke_dialog_ui_button")[6].click();

More info: I am writing chrome-extension to inject javascript function that could "click()" appropriate buttons. 更多信息:我正在编写chrome-extension以注入可以“单击()”适当按钮的javascript函数。 Since I am ready to build extension, there must be a way to bypass security. 由于我已经准备好构建扩展程序,因此必须有一种绕过安全性的方法。 Any help will be appreciated. 任何帮助将不胜感激。

Thank you! 谢谢!

When the file picker dialog pops up, you can't control it with javascript, and in an input type="file" you can't also set its value because that would be a security risk. 弹出文件选择器对话框时,您无法使用javascript对其进行控制,并且在输入type =“ file”中,您也无法设置其值,因为这会带来安全风险。

You need to move to an environment with higher permissions in order to fully achieve what you want. 您需要移至具有更高权限的环境,才能完全实现所需的功能。

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

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