Importing a folder of images

Hello everyone,

I would like to know what would be the best way to import a folder containing subfolders of images in a SQL database using Servoy (to mimic a functiunality in FM). Could someone point me in the right direction for a method to do this? Or to the SQL syntax I would need to put all this in iAnywhere, perhaps? And how would I keep a record of the original path of the files?

TIA,

Ben

Hi Ben,

Use the “file” plug-in to allow the user to specify the directory. You can then also use other functions in the file plug-in to get the contents of a folder (or sub-folder), then you can loop through the contents and read in the binary data, and create a record for it programatically. You can also access the info about the individual file (name, extension, size, mod date, etc.) - similar to the Troi plug-in in FMP.

Here is a method I used a while ago. I used a method that I found on this forum and tweaked for my own purposes.

Hope it helps.

Best,

Rich Coulombre

// Get the folder to import from
var theFolder = plugins.file.showDirectorySelectDialog();
var theFolderName = theFolder.getName()

// Did we select something or not
if ( theFolder )
{
// Get all the files according to the filter array (jpg and JPG)
var theFolderContents = plugins.file.getFolderContents( theFolder, [‘jpg’,‘JPG’, ‘png’, ‘PNG’, ‘gif’, ‘GIF’]);

// Loop through the fetched array with files
for ( var i = 0 ; i < theFolderContents.length ; i++ )
{
// extra check if this file is indeed a file and not a folder
if ( theFolderContents*.isFile() )*
{
// Create a new record in the current form
controller.newRecord();
// put the image in the field and collect other meta data about image

_ var theFile = theFolderContents*;_
file_name = theFile.getName();
media_data = plugins.images.getImage(theFile);
collection_name = theFolderName;
_
}_
_
}_
_
}*_

Thanks for the sample code, Rich!

HI Ben.

If you don’t want to write any new functionality, you could use the ImageBean. The ImageBean ships with the MediaManager that allows you to DnD folders onto the bean and import them for you. It gives you visual feedback during import as it creates records and then displays attributes such as mime-type file-size in the bean itself directly after the record has imported.

It’s a “product plug”, I guess, but the functionality that you want is already there, so it seems suitable to suggest it here.

Take a look at :
http://forum.servoy.com/viewtopic.php?t=6516

You will find a hyperlink to the website which shows some demo “Media Manager Plugin” movies. I think it’s either the 2nd or 3rd mopvie that demonstrates this.

Once data are in the record, then simply swap to a form where you show the ImageBean and your content is streamed out automatically. Once on a Form with the ImageBean, you can always change the content there via DnD.

Thanks a lot guys for your quick replies, and especially to Rich for your sample code - I just changed ‘theFolder.getName()’ to ‘theFolder.getPath()’, and KaplangPow! It works like a charm :!: I’m sure your plugin will come in handy also, cybersack.

Servoy really rocks!

Ben