09.12.2021 How to edit the BLOB editor and copy paste

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2021-12-09 10:49

Hello
I want to be able to copy and paste into a blob text field.
With text, images, links .. it is for example to make tutorials with screenshots.
I do my capture, copy and paste afterwards.
I know that it is possible for example here:
https://www.sceditor.com/
Can we do it with APPGINI?

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2021-12-09 11:04

I make a screenshot
I make a COPY
I go to my APPGINI application, BLOB field I paste, the image appears, I SAVE the image disappears.

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-01-04 08:41

hello
No idea ?

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pbottcher » 2022-01-04 17:11

Hi,

do you only need the data to be shown in the DV? or also in the TV?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-01-10 10:01

Hello
In detail DV this would already be very good. :D

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-01-10 10:05

10012022  1 Capture d’écran 2022-01-10 110415.png
10012022 1 Capture d’écran 2022-01-10 110415.png (66.17 KiB) Viewed 5318 times
10012022 Capture d’écran 2022-01-10 110415.png
10012022 Capture d’écran 2022-01-10 110415.png (18.17 KiB) Viewed 5318 times

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pbottcher » 2022-01-10 18:39

Hi,

you can try this: Add to the hooks/TABLENAME.php -> _dv function

Code: Select all

	if ($selectedID) {
		$blob=sqlvalue("SELECT FIELDNAME from TABLENAME where PRIMARYKEY={$selectedID}");
		$html.="<script>\$j(function() {\$j('#FIELDNAME').val('".$blob."')})</script>";
	}
Replace FIELDNAME , TABLENAME , PRIMARYKEY with your data.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-02-01 07:12

Perfect ! merci

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-02-07 16:03

2.png
2.png (72.78 KiB) Viewed 4690 times
Hello
Not everything is solved and it's very weird.

I make a copy paste of an image (145kB) APPGINI does NOT save it, I make the same collage through a forum type SMF SIMPLE MACHINE FORUM, it works!

I PASTE in SMF then I copy (ctrl + c) then I go to APPGINI, I make a PASTE (CTRL + V) and there miracle it saves me!

What for???
Attachments
3.png
3.png (192.38 KiB) Viewed 4690 times
4.png
4.png (139.84 KiB) Viewed 4690 times

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pbottcher » 2022-02-08 07:43

Hi,

sorry, I did not get your use case. Can you please explain the steps you do, so I may try to reproduce it.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-02-08 08:33

Hello
1) I make a screenshot with the WINDOWS CAPTURE tool, then COPY in the CAPTURE tool, COPY button or CTRL+ C

2) I go to my APPGINI online application and in the relevant field (BLOB) I make a PASTE (CTRL + V), my image appears. I save it disappears...

3) I do the same thing through another site where IS INSTALLED SIMPLE MACHINE FORUM SMF (forum like PHBB), I paste my image, and I make a COPY of the entire article (CTRL + A and CTRL + C)

4) I return to my online application APPGINI, I make a PASTE (CTRL + V), my article appears and I save and there miracle: my image is preserved!


User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by jsetzer » 2022-02-08 10:12

Your use case #1

In TABLENAME_dml.php there is some sanitizing of database data. I guess this is one more security feature for avoiding Cross Site Scripting (XSS).

Find the lines where it says...

Code: Select all

$urow = $row; /* unsanitized data */
$row = array_map('safe_html', $row);
The second line iterates through all array items (AKA record values) and removes a lot of HTML tags. You can check by yourself if you dump out data before and after safe_html() has been applied.

Code: Select all

$urow = $row; /* unsanitized data */

$cn ="description"; // this is the column name
var_dump($row[$cn]);
$row = array_map('safe_html', $row);
var_dump($row[$cn]);
exit;


In my test this was the result:

chrome_G5PrViHbXk.png
chrome_G5PrViHbXk.png (41.52 KiB) Viewed 4648 times

We can clearly see that the image-data came from the database but then was removed by applying safe_html function.

For proof I have skipped html-sanitizing by commenting out the line ( :!: Caution: don't do that in production!) ...

Code: Select all

$urow = $row; /* unsanitized data */
// $row = array_map('safe_html', $row);
...and then the image gets rendered as expected.

chrome_hinXdFldiq.png
chrome_hinXdFldiq.png (20.47 KiB) Viewed 4648 times

So, this is the reason why pasted images will not be displayed in nicEdit after reloading the page.

Your use case #2

Next to this first issue, you have reported that copied images from a different system get saved and restored on reload. I have taken a look at safe_html() function and there is a lot of functionality and parsing and regular expressions being executed for stripping html tags. I did not investigate, I can only guess that, in your second use case, you don't copy and paste binary image data, but a reference to an image, stored on a remote machine.

Exkurs: in Windows OS, when copying something into the clipboard, the clipboard contains the copied item in multiple available formats (dataFormats), for example as plain text, as richtext, as binary data. When pasting, the target accepts only supported dataFormats and takes the best matching dataFormat. For example Notepad accepts plain text only, but Wordpad also accepts Richtext.

As said before, I cannot promise that this is the reason in your 2nd usecase. You can find out by dumping $row before and after sanitizing. Then we should be able to see differences, if any.

Summary

In this first step I have searched for, found and named the reasons. Let's see your var_dump() results of your 2nd use case. As soon as we know the reason, we can try to find fixes for both use cases.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pbottcher » 2022-02-08 12:35

Hi,

also I fully agree with Jan's explanations, I think to this issue the solution is simpler. You use a BLOB and want to store 145kb. According to the docs.

BLOB: A binary large object column with a maximum length of 65535 (2^16 - 1) bytes, or 64KB in storage. Each BLOB value is stored using a two-byte length prefix that indicates the number of bytes in the value.
MEDIUMBLOB: A binary large object column with a maximum length of 16777215 (2^24 - 1) bytes, or 16MB in storage. Each MEDIUMBLOB value is stored using a three-byte length prefix that indicates the number of bytes in the value.
LONGBLOB: A binary large object column with a maximum length of 4294967295 (2^32 - 1) bytes, or 4GB in storage. Each LONGBLOB value is stored using a four-byte length prefix that indicates the number of bytes in the value.

The image you try to store is just too big. So either you need to change your type for this field, or need to drop the size of the image.
I guess if you use the other system, the image is already compressed within that system and hence if you copy the image after saving to the other system and retrieving the image again, you will have an image with a smaller size that fits the BLOB capacity.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-02-08 13:15

I don't think it's a big problem, I've tried and always the same problem.

On the other hand if I look where is the image I paste (step 2 with SMF) I realize that this image is stored on www.i-imgur.com) so in my opinion it is a link, but it is completely transparent.

View image


imgur2.png
imgur2.png (7.32 KiB) Viewed 4631 times

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-02-08 13:28

Simple Machine Forum must send the image to i-imgur.com automatically and then retrieve the link... it's fast and convenient. I read that there is an API for that.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by jsetzer » 2022-02-08 13:33

I had set up my testing column as long blob and the problem was the same.

So the image size will become a problem when having sum(all content) > 4GB, as pböttcher has mentioned completely correct.

But even with smaller image sizes safe_html() strips out embedded images (base64 encoded data).

Your variable dump seems to proof my guess: after copying from different system (SMF) and pasting into nicEdit not the image itself but the href was pasted. This means you just have a hyperlink and rely on availability of that image over the network on the remote machine. It depends on your requirements if this is good or bad. Personally I'd like to be able to have the image itself (binary), not only the link.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-02-08 13:40

Oui JAN mais comment avoir cette image en binaire ?

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by jsetzer » 2022-02-08 13:47

Please post in Englisch.

We have more than one problem to solve. Right now I don't know any bulletproof, copy & paste ready, hooks only solution, fixing all problems.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by jsetzer » 2022-02-08 14:02

Sorry, I could not append to my prev answer. Forum denied saving

(Continued)

A good solution will have to...
  • ...sanitize all data but keep base64 encoded images in richtext fields
  • ...intercept pasting image hrefs, then download image, base64-encode data and paste <img/> having binary data instead of href
  • ...deny pasting images if (content size + new image size) is bigger than max. of that field
It should...
  • ...not be overwritten on next code generation
  • ...be compatible with different image formats
  • ...allow sizes depending on max. field size
Right now I don't know any bulletproof, secure, copy & paste ready, hooks only solution, fixing all problems.

Anyone else having ideas?
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-02-08 15:04

Now that I have understood how image hosting works as on SMF, I will look for a solution to adapt to APPGINI.

As here for example

https://forum.forumactif.com/t381038-u ... r-d-image

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by jsetzer » 2022-02-08 15:32

Great! I'm looking forward to your solution.

In between I have asked Ahmed about that safe_html() function and supporting base64 encoded images. Gonna report when I got an answer.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pbottcher » 2022-02-08 16:24

Hi, just a short question. What version of AppGini are you running?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pasbonte » 2022-02-08 16:49

Version 22.11

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: 09.12.2021 How to edit the BLOB editor and copy paste

Post by pbottcher » 2022-02-09 08:29

Hi again,

to be honest, I cannot reproduce your error. It just works fine as long as the settings are correct. Maybe you have additional code that acts. But with the native installation and the code provided above, it just works fine.
appgini_img.gif
appgini_img.gif (216.24 KiB) Viewed 4616 times
Maybe you can post the code you have added.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Post Reply