Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
83 views
in Plugins by
edited by

Hi,

I came across this issue myself, and noticed a lot of people had it, yet I did not come across any `full` solutions:

a good Related discussion (among many):
https://www.question2answer.org/qa/96011/how-to-add-an-image-to-a-question-answer?show=96011#q96011

https://www.question2answer.org/qa/113323/auto-upload-of-copy-pasted-images?show=113323

The issue summarized:
- When pasting an image, the Ckeditor will convert it into base64 therefore exceeding the 12000 characters limit Q2A has by default (due to DB limitations)
- Same issue with Drag and drop.


My solution:

Ckeditor allows you to disable the default behavior and use an included plugin https://ckeditor.com/cke4/addon/uploadimage but it requires some tweaking. Full solution posted below.
 

Q2A version: 1.8.8

1 Answer

0 votes
by
 
Best answer

My full solution:

1- Backup your Q2A directory and clone it to test on a different installation.

2- Optional: install the latest Ckeditor, head to your q2afolder/qa-plugin/wysiwyg-editor, rename the ckeditor folder to something like ck-, download  the version that suits you from here, or even add more plugins using the customize option via the online builder (I personally added code editors and other fancy stuff) https://ckeditor.com/ckeditor-4/download/#ckeditor-4-lts

Then extract the new ckeditor folder from that zip, in the qa-plugin/wysiwyg-editor folder in lieu of the old one.
@todo feel free to merge with old style.js/config.js from the included editor

3- Now head over to your (new) qa-plugin/wysiwyg-editor/ckeditor, modify config.js content to the following:

CKEDITOR.editorConfig = function( config ) {

config.extraPlugins = 'uploadimage';

config.uploadUrl = 'uploader.php';

};

if you already have content inside your editorConfig block, do not overwrite it! Just add these extra 2 lines above.

This config option tell ckeditor to treat pasted images with the uploadimage plugin, and to proceed to uploading them via the uploader.php script (that we will create in the next step)

4- now head to the root of your q2a installation and create the uploader.php file and create a folder with write permissions to your webserver call it "uploads"

and put the following in your uploader.php


https://pastebin.com/JgHPhNa2

5- if you followed everything correctly, your new editor will now paste <img src=...> tags with a url to your image instead of massively long base64 

Alternatively, you can use a (paid) service like their https://ckeditor.com/docs/ckeditor4/latest/guide/dev_easyimage_integration.html

It is easier to configure; no need to write the uploader.php file, but you do not host the images yourself locally, they are stored on their servers, which depending on your use-case and might be a good or a bad thing (privacy constraints/regulations, etc).

- Please follow carefully, make sure to test on a test environment before your production server. 
- Make sure to understand what you do, and read before pasting/clicking things.
- I am not responsible if you break your website.

I am no expert in q2a, just shared the way I solved a problem so that people can use it for inspiration and possibly more knowledgeable people will post comments and improvements !

...