BLOB datatype

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
mekin
Veteran Member
Posts: 40
Joined: 2019-04-22 17:09

BLOB datatype

Post by mekin » 2019-12-04 09:18

Hello, I want to get images into the DB as a BLOB type, not as an image.
This is for a tool we build documents and the image-functionality of this tool works onlt if the image is imported in bytes.

If I set a field in AppGini as a BLOB and I upload an image, then the image doesn't get into the record as a binairy format, but as a bin-file.
If I update the record with PHPMyAdmin and upload the same file, then it shows as binairy data in the field.

Can someone tell me how the BLOB datatypes works in AppGini or how I can upload an attachment as binairy data?

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: BLOB datatype

Post by onoehring » 2019-12-04 12:56

Hi mekin,

did you test: Download an image that you have uploaded to AG - does your tool work? Maybe it's only a different label.
BTW: I would recommend NOT to save images to the database.
Olaf

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

Re: BLOB datatype

Post by pbottcher » 2019-12-04 12:59

Hi,

the image in AppGini is stored as a file on the filesystem. Hence if you want to store it into the DB, you can use the after_insert/after_update hook,
read the file (image) for that record from the filesystem and put it into the blob field. You should not use the same field, as in the image field, the filename of the uploaded file is stored.
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.

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

Re: BLOB datatype

Post by jsetzer » 2019-12-04 13:12

This is not a trivial task:

After Insert/Update, as pböttcher has mentioned a minute ago, you will have to read all bytes from uploaded image, then insert/update the BLOB field bytewise using SQL. Afterwards you can delete the file from disk to reduce required space.

You will need two fields in you table:
  • an image-upload field
  • a BLOB field
But this is only the first part or the task:

If you want to show the file in your table view or detail view of your AppGini app, this will not work out of the box any more, if the file has been deleted.

Sure, on access, you can once again save the bytes back to your folder, then change the imagefield-content. And don't forget to prepare the thumbnails if this is an image. But this does not really make sense especially in multi-user environment with concurrent access.

So due to this, you definately need the binaries on disk if you want to show or download them. Additionally storing them in db as BLOD doubles the volumn on disk and slows the system down because of storing and restoring files on every access.

Summarizing: You can do this with hooks, as pböttcher said, but there will be some hurdles concerning performance, disk space and concurrent access.
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

mekin
Veteran Member
Posts: 40
Joined: 2019-04-22 17:09

Re: BLOB datatype

Post by mekin » 2019-12-04 13:30

Hi, if I upload it with AppGini, then I can look it up and it shows the image with the url to the website.url/images/randomID.jpg
But when I look it up with PHPMyAdmin, then I can only download a image.bin file where the name of the file is in this file, not the image itself.

But as I wrote earlier, If I upload the image with PHPMyAdmin, then I can download a bin-file where the binairy code of the image is in this file.
This is what I want, because my Document Builder software reads this binairy code and places the image with the right settings in the document it creates.

mekin
Veteran Member
Posts: 40
Joined: 2019-04-22 17:09

Re: BLOB datatype

Post by mekin » 2019-12-04 13:33

Hi Jan, just missed your post.
I will look up this issue and take all of your tips in it, thanks!

I'll be back.

mekin
Veteran Member
Posts: 40
Joined: 2019-04-22 17:09

Re: BLOB datatype

Post by mekin » 2019-12-05 06:56

Also a reply to pbottcher, I missed also your post yesterday.

It's not a NASA database, so the images that are going to be stored are not that much.
Also it would be nice to shrink the images at time of conversion to BLOB, so a 6 MB image can be reduced to 200 KB.

Post Reply