| 2 | |
| 3 | Following [https://github.com/ckeditor/ckeditor-dev/blob/major/plugins/filetools/plugin.js#L463-L471 this] example I tried to customize a bit my request object. I end up with: |
| 4 | |
| 5 | {{{ |
| 6 | CKEDITOR.replace( 'editor', function() { |
| 7 | CKEDITOR.fileTools.fileLoader.prototype.sendRequest = function() { |
| 8 | var formData = new FormData(), |
| 9 | xhr = this.xhr; |
| 10 | |
| 11 | formData.append( 'upload', this.file, this.fileName ); |
| 12 | xhr.withCredentials = true; // Extra lines |
| 13 | xhr.setRequestHeader( 'X-PINGOTHER', 'pingpong' ); // Extra lines |
| 14 | xhr.open( 'POST', this.uploadUrl, true ); |
| 15 | xhr.send( formData ); |
| 16 | }; |
| 17 | } ); |
| 18 | }}} |
| 19 | |
| 20 | Shortcomings of this solution are: |
| 21 | * We overwrite global function `sendRequest` which influence all editor instances while option`imageUploadUrl` is unique for all editor isntances. |
| 22 | * We have to wait for plugin to be loaded and editor instance as well to overwrite this method. If user have got a few editors he have to impelement special mechanism to overwrite this function when first editor instance is loaded. Or maybe there is a global event which fire when plugin is loaded? |
| 23 | |
| 24 | We got at least two sulutions for this: |
| 25 | * We can add extra config option like: |
| 26 | {{{ |
| 27 | xhrData = { |
| 28 | withCredentials: true, |
| 29 | headers: { |
| 30 | 'X-HEADER-NAME': "X-HEADER VALUE" |
| 31 | } |
| 32 | }; |
| 33 | }}} |
| 34 | |
| 35 | And function send request will take into consideration {{{xhrData}}} config options and set flag and headers. This is simples solution but don't allow user whole freedom. |
| 36 | |
| 37 | * Second option is to fire events like `prerequest` which will have an xhr object as a property and user would make whatever he wants with this. |