简体   繁体   中英

How to add a csrf token to a post request in a image upload in CKEDITOR plugin?

I am using a enhanced image plugin to upload the image to the server.My backend is Django.By taking some help from django-ckeditor I have implemented the frontend and backend part of image upload in CKEDITOR.

However Django-Ckeditor does not handle csrf protection in image upload. It uses csrf_exempt decorator to exempt from csrf protection.

upload = csrf_exempt(ImageUploadView.as_view())

How to add csrf token to the post request which is made for image upload?Will I have to write my own form in the upload plugin which handles csrf token?

The easy way is to add csrf token in filebrowserImageUploadUrl, see below (jsp)

$(document).ready(function() {
   var editor = CKEDITOR.replace('content', { skin: 'moonocolor',
      toolbar: 'MyToolbar', 
      filebrowserImageUploadUrl: "<c:url value="/site/upload"/>${_csrf.parameterName}=${_csrf.token}" });
   }
});

我只是简单地将csrf标记连接到我的上传网址:

filebrowserImageUploadUrl: '/laravel-filemanager/upload?type=Images&_token=' + $('meta[name=csrf-token]').attr("content"),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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