Stored images not displaying in IMAGE_MEDIA field

I just downloaded the demo version of Servoy a couple of days ago…I’m trying to see if I can get our office to switch over to it from FileMaker, without losing our less-computer-oriented folks in the process, who would be maintaining the database. Anyway, everything looks great, but I’ve run into an issue…

I have JPEG images stored in a MySQL BLOB field. So, in a Servoy form, I have an IMAGE_MEDIA field that I want to display the JPEG stored in the BLOB. When I go to any of the records that have an image store in the BLOB field…the images do not appear.

Now…I can load a new image from a file into this IMAGE_MEDIA field, and then the loaded image will display inside the field. This does also update the data inside the BLOB field for that record. I can continue to see the image when viewing this record until I close Servoy. Then when I reopen Servoy, it won’t show the image at all, and I’m right back where I started.

Is there anything I could be doing wrong? I’m able to look at all of the images by using the MySQL Query Browser software, etc., so I know that the image data is being stored correctly in the database. Thanks for the help.

is the blob really big enough?

What happens if you upload it (and then restart servoy)
Then start servoy again and dump the byt to disk for that record that you just uploaded. (use File plugin for writing the byte to disk)
Is it then the exact same file? (size)

I’m writing a 6.7KB JPEG into a MySQL MEDIUMBLOB (maximum size: 16,277,215 bytes). Again, I can see the JPEGs fine from the database, using MySQL Query Browser – they are all getting stored in there correctly – it just won’t show them in Servoy.

Also I’m sure this is simple, but I haven’t gotten around to making any methods yet…what do I need to call to get the data out of a field in the current record in my form? To get the data from a field named ‘photo’ from a form named ‘Students’ I thought I needed a line like:

var success = plugins.file.writeFile(‘y:/image.jpg’, forms.Students.selectedrecord.photo);

but that’s not quite working, saying that selectedrecord is undefined and has no property named photo (even though I can see it with the Editor). Thanks.

what is that selectedrecord?
You didn’t move or used codecompletion for that:

var success = plugins.file.writeFile(‘y:/image.jpg’, forms.Students.photo);

selectedrecord node is just as relations node. It is just a container with stuff. Where you can click on to move code, It is not also a javacript object.

What kind of field do you use for the media to display. I have no idea why it doesn’t work for you, if you use a IMAGE_MEDIA field it should display it just fine.

Not sure if this is relevant… recently I’ve been working with a solution with a bunch of blobs, and discovered that MySQL has a default max packet size of 1MB. Added the following statement to the my.ini file and it solved our problems:

max-allowed-packet=8M

Depending upon which version of MySQL you are using the value can be set much higher.

Best,

Rich Coulombre

“if you use a IMAGE_MEDIA field it should display it just fine”
Exactly … totally agree … that’s why I don’t understand why this isn’t working. :)

When I make that correction to my method, the error goes away, but writeFile returns false … ?
var success = plugins.file.writeFile(‘y:/image.jpg’, forms.Students.photo);

Rich, thanks for the tip, unfortunately I do not have access to modify my.ini as the website is hosted by another party. Do you think this would affect things for small images < 1 MB?

very small images should go ok i guess but only if the blob size is now to small.

Save the file to c:/ (don’t know what y:/ is or something)
also

application.output(forms.Students.photo.length) what does that print?

Small images should be fine… we only had problems with particularly large images…

hmmmm…

best,

Rich

Hmmmm… when I restart Servoy and the photo isn’t showing up,

application.output(forms.Students.photo.length)
``` throws:

> The undefined value has no properties calling length.

Or, if I have the debugger enabled:

> TypeError: Cannot convert null to an object.

After I load the image into the form from a file, so that I can see the image until I restart Servoy ... the return value is 7068.0, which is exactly the same file size as my image according to Windows Explorer.

What in the world am I doing wrong? I just want to display a photo on a form like everyone else ... <img src="{SMILIES_PATH}/icon_sad.gif" alt=":(" title="Sad" />

Hi, I have used images in mySQL without any problem. I use PostgreSQL for almost everything and PostgreSQL, like mySQL, has many more data types than you can create from inside Servoy. Whenever I come across a problem I try the following:

Create a test table from inside Servoy. In your case, add an imagemedia field. Check that the form works. Important: avoid writing any code at this point, just store an image using the built-in Servoy functionality.

Take a look at the resulting mySQL table to see what type Servoy images default to…

Sorry to re-open an old thread, but I was out of the country for a few months and haven’t been able to mess with this since then. Here goes…

I did a fresh install of MySQL 5.0.27 on my laptop (before, I was connecting from Servoy Developer on my laptop to MySQL 4.1.18 on another server). I’m running Servoy Developer 3.0.2-build 373. I created a brand new solution. When I got to the MEDIA field, I ran into the same problem as before.

In response to swingman’s message, when I go into “Tools” > “Dataproviders” in Servoy, and create a MEDIA field (without entering a size value), a LONGBLOB field is created in the MySQL database table. However the same problem continues to occur, even if I change the source of the MEDIA field in my Servoy form to the MySQL field that I created from within Servoy.

I’ve loaded files of various sizes and formats into the field using the Servoy form, by right clicking the field and selecting “Load Image”. After I save the data by pressing F6, I am able to see the image in the database on my laptop, using MySQL Query Browser. That’s working fine.

But if I close Servoy Developer, or if I switch into and then back out of Designer view…the picture no longer appears in the field in Servoy. But it’s still stored in the database. All of my other text fields are populated correctly for the row by Servoy.

Almost all of these pictures I am using are far below the max_packet_size setting of 1MB in my.ini for MySQL Server. (I read somewhere that the JDBC driver doesn’t have a separate max_packet_size setting; it matches the server it is connecting to.)

I shouldn’t have to tell this form somehow to retrieve and display the contents of a MEDIA field, right? As long as the contents of a MEDIA field is not null, it should do that automatically?

Thanks again for your help.

make a sample solution with some export data and make a case with that in our support system. Tell us that we need to test it on MySQL specifically

Is it still the case that you can’t do:

application.output(forms.Students.photo.length) ?

Because that means that the image isn’t stored (but you see it with other tools) or can’t be read back somehow because if you get

The undefined value has no properties calling length.

then photo is null and wasn’t loaded.