简体   繁体   English

ckeditor :上传图像时设置标题

[英]ckeditor : set header while uploading an image

I am using CKeditor 4. In that Image plugin.我正在使用 CKeditor 4。在那个Image插件中。

I have removed unwanted tabs on Image popup and also set the config.filebrowserImageUploadUrl to my server's URL.我已经删除了图像弹出窗口中不需要的选项卡,并将config.filebrowserImageUploadUrl设置为我的服务器的 URL。

Now I have to upload the image, I am able to select the image, then when I click on Send it to server button, AJAX call goes to my server, But my server requires a particular header set for authentication.现在我必须上传图像,我可以选择图像,然后当我单击“ Send it to server按钮时,AJAX 调用会转到我的服务器,但是我的服务器需要一个特定的标头集进行身份验证。

Question is - can I set the header before sending that request ?问题是 - 我可以在发送该请求之前设置标头吗?

If you are using CKEditor version 4.9 + then there is one way you can do this.如果您使用的是CKEditor version 4.9 +那么有一种方法可以做到这一点。

I faced the same problem while working, so after some search and trying some code samples I found the way.我在工作时遇到了同样的问题,所以经过一些搜索和尝试一些代码示例后,我找到了方法。

There are some configurations that you have to set,您必须设置一些配置,

again I repeat this is for CKEditor version 4.9 + .我再次重申这是针对CKEditor version 4.9 +

set below configuration in your ckeditor config objectckeditor配置对象中设置以下配置

{
     filebrowserUploadUrl : 'your upload path goes here',
     filebrowserUploadMethod: 'xhr',             
     fileTools_requestHeaders: {
           'X-Requested-With': 'XMLHttpRequest',
           'your_custom_header_name': 'custom_header_value' 
     }
}

I will attach a reference here我会在这里附上参考

fileTools_requestHeaders fileTools_requestHeaders

filebrowserUploadMethod 文件浏览器上传方法

In the code sample above,在上面的代码示例中,

filebrowserUploadUrl : is the api-url that ckeditor will call while uploading filebrowserUploadUrl : 是 ckeditor 在上传时调用的 api-url

when uploaded ckeditor emits fileUploadRequest event,当上传的 ckeditor发出fileUploadRequest事件时,

you can change/set headers after catching that event too.您也可以在捕获该事件后更改/设置标题。

filebrowserUploadMethod : when set to 'xhr', it allows you to set the extra headers, by default value will be 'xhr' only. filebrowserUploadMethod : 当设置为 'xhr' 时,它允许您设置额外的标题,默认值仅为 'xhr'。

The default upload tab of CKEditor doesn't use any AJAX call to upload files. CKEditor 的默认上传选项卡不使用任何 AJAX 调用来上传文件。 It's just an iframe with a normal form and file input, so you can't change the request headers.它只是一个带有普通表单和文件输入的 iframe,因此您无法更改请求标头。

If you want to upload files with an AJAX call then you must write your own code or use the SimpleUploads plugin , and configure it to your needs.如果您想使用 AJAX 调用上传文件,那么您必须编写自己的代码或使用SimpleUploads 插件,并根据需要对其进行配置。 (disclaimer: I'm its author) (免责声明:我是它的作者)

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

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