E
E
Elvis2017-03-15 15:20:46
Django
Elvis, 2017-03-15 15:20:46

How to implement image loading by pasting from clipboard?

In the admin panel (content creation) I use django-tinymce.
The original content comes to me in a Word document (well, yes, it comes like that, what can I do). With the help of otherworldly forces, I insert all the text from word into the field for the article. the formatting is transferred as needed (well, I edit the html a little later). However, pictures are not transferred. With a little Google search and a few tests, I realized that it is impossible to insert text and an image at the same time. either one or the other. Separately, then I insert pictures, with a simple pop-up directly from the word document.
Everything is displayed, everything is fine from the user's side.
However, if you look at the html code of the result page, you can see that the images are data:image/png;base64. On the one hand, it seems to be nothing terrible, but the page starts to weigh quite a lot and it hardly affects seo.
There was a question about the implementation of such functionality:
- on the same form for adding an article, make an additional field (probably using jQuery, since I will not need this information in the database)
- when inserting an image into the field - this image is uploaded to the server in a specific folder
- in another field (or to the clipboard) we get a link to this image for insertion into html, or the entire img tag is direct, it doesn’t matter.
Is there such magic already implemented or where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Kazantsev, 2017-03-18
@Dr_Elvis

Well, you take and parse html in the overridden save method of the model (or you can use signals) and save these data:image/png;base64 as pictures and replace src in html with the image path.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question