I want to create a program that allows a user to upload an image (png) and have it stored in my PostgreSQL database. I already created a table/column for it. Table name is "images". I set the datasource of the form to this table. There are 2 columns. id (integer) and imagedata (bytea)(bytea is the column type Servoy creates for MEDIA). Then I created a button that will open a "showFileOpenDialog". When the user selects a file and then presses "upload", the callback function is called. The callback function sets the mediaDataProvider to the JSImage. This mediaDataProvider is used by a media element on the form. The image shows up on-screen in this media element as expected. Then the function tries to store the JSImage data to the PostgreSQL database.
I can never get the image data to work from the database. I am not sure if it is having trouble writing TO the database or getting the image data FROM the database. I have been able to read/write everything else from the database just fine, just not image data. Here is the code.
function buttonOnClick(event)
{
/** @type {JSFile} */
plugins.file.showFileOpenDialog(1, path, false, "*.*", callbackFunc, "Pick an image to upload")
}
function callbackFunc(jsfileArray)
{
var image1 = plugins.images.getImage(jsfileArray[0].getBytes())
mediaDataProvider = image1 //this makes the image appear in a media element successfully. No problems yet.
/** @type {JSRecord<db:/junkdata/images>} */
var record = foundset.newRecord(false)
record.imagedata = image1.getData() //Is this what is failing?
databaseManager.saveData(record)
}
Then I have another button on the form that will trigger this code:
mediaDataProvider = plugins.images.getImage(foundset.imagedata) //This NEVER works. The media element goes blank. Anyone have some advice?