3

I have a CKEditor on different pages of the site, so I settled up the uploads to true and all the configuration stuff for it to work, and the image upload worked just fine for "Send it to the Server" tab. But from here I want to intercept or interact with upload function to be able to upload images not to a folder, but into database with some flags like "page" where is image uploaded, "category", "cropping" and some another manipulations with them.

So how could it be done to intercept this uploads?

I was curious and I found that the default action for uploads is

/%project_name%/ckeditor/upload.html?CKEditor=textarea_1457018535&CKEditorFuncNum=2&langCode=en 

and the action for this uploads is CkeditorUpload.java, but I don't realize how can I use them further.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Denees
  • 9,100
  • 13
  • 47
  • 76
  • Will not work to intercept, means you don't need to write an interceptor for it. But have to write implementation. What did you try? – Roman C Nov 23 '13 at 18:42
  • By "intercept" I didn't mean to write an interceptor, but to INTERCEPT that action of upload whatever it is AJAX request or Struts action or something else. – Denees Nov 24 '13 at 12:43
  • Do you mean that *intercept* is to bypass the action execution or what? – Roman C Nov 24 '13 at 13:39
  • hmm, not so much bypass, but to overwrite (override) it – Denees Nov 24 '13 at 13:52

1 Answers1

1

Well, if you'd like to override it you should start overriding the method execute from the action class above. Also override the configuration by replacing the class reference in the action configuration. The point is where the original implementation creates FileOutputStream should be replaced to ByteArrayOutputStream. Then let it write to the byte array stream and getBytes() from it will give you byte[] data. Save that data to the database. You may also read this answer will help you to do it or this tutorial will explain you how to do it with Hibernate. Then the code where the action writes HTML change the disk path to the action path /uploads mapping to the action which retrieves the image from the database. Example of the ImageAction you can find here. This answer will also helpful.

Community
  • 1
  • 1
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • thanks for that. The only point I want to know is how to interact with CKEditor's image upload, otherwise I don't have any problems with saving it to the database, but thanks anyway. The defaultStack in my configuration has , how I can get the data from there now? or I need to configure some sort of a listener? – Denees Nov 24 '13 at 18:33
  • The `upload` property should be populated with this interceptor. – Roman C Nov 24 '13 at 18:41
  • I think I can't get the right point of your idea, I find it hard to understand what you're trying to say, sorry for that. – Denees Nov 24 '13 at 19:10
  • May be [this](http://struts.apache.org/release/2.3.x/docs/file-upload-interceptor.html) explains better? How to interact, did you use their showcase? Image properties contains a tab upload and you can upload it on server via a button then press ok and uploaded image linked to the text. I have uploaded two images there and links are valid but it doesn't show donowhy. – Roman C Nov 24 '13 at 19:16
  • CKEditor uses his own action for Uploading files which is integrated in the library itself, I don't have access there, if I do had I didn't asked for this ever. – Denees Nov 24 '13 at 21:44