HOW TO: put files in blob and after that, open them!

Hi all, here is a HOW TO: put files in blob and after that, open them right away

BTW this is only working in 2.0beta5

make 4 fields:
bestandspad TEXT 200
bestandsnaam TEXT 50
bestandgrootte INTEGER
media (IMAGEMEDIA)

To put files in the blob an fill the appropriate fields do this:

controller.newRecord()
filename = application.showFileOpenDialog(); 
if (filename)//for cancel 
{ 
	var normalizedFileName = "";
	normalizedFileName = utils.stringReplace(filename,'\\','/')//make windows path like unix path 
	bestandspad = normalizedFileName

	var idx = normalizedFileName.lastIndexOf("/"); 
	if (idx != -1) normalizedFileName = normalizedFileName.substring(idx+1 );
	bestandsnaam = normalizedFileName
	media = application.readFile(filename)
	bestandgrootte = plugins.file.getFileSize(filename)
}

after that, make a method that opens the files right away from out the database:

var a = bestandsnaam.lastIndexOf(".")
var b = bestandsnaam.substr(0,a)
var c = bestandsnaam.substring(a)

var filename = application.createTempFile(b,c)
application.writeFile(filename,media);

if(utils.stringMiddle(application.getOSName(),1,7) == "Windows")
{
	application.executeProgramInBackground('rundll32', 'url.dll,FileProtocolHandler',filename)
}

Mabey someone can make the last method compatible with Macintosh or Linux/Unix.

Tack this onto the end for Mac:

else
{
if (utils.stringLeftWords(application.getOSName(), 1) == "Mac")
{
	application.executeProgram('open', filename);
}
}
  • david

david:
Tack this onto the end for Mac:

Thank You, David :D

david:
Tack this onto the end for Mac:

else

{
if (utils.stringLeftWords(application.getOSName(), 1) == “Mac”)
{
application.executeProgram(‘open’, filename);
}
}




- david

Does anybody has an idea to how make a similar code to work under Linux? I tried to use the open command, but it seems to have no effect (even if I try to use it from a terminal window).

Best thing to do is ask them what application they want to open the file, and possibly substitute %s with the filename. Once they’ve answered this question once, remember it.

For example, on my unix install, images could be displayed with a variety of programs:

gimp %s
mozilla %s
firefox %s
xv %s
display %s

Personally I prefer xv or mozilla. Others prefer firefox.

Also you can do all kinds of options this way, for example:

myprogram --filename %s --myotheroption someothervalue

Sebastiaan van Erk

sebster:
Best thing to do is ask them what application they want to open the file, and possibly substitute %s with the filename. Once they’ve answered this question once, remember it.

For example, on my unix install, images could be displayed with a variety of programs:

gimp %s
mozilla %s
firefox %s
xv %s
display %s

Personally I prefer xv or mozilla. Others prefer firefox.

Also you can do all kinds of options this way, for example:

myprogram --filename %s --myotheroption someothervalue

Sebastiaan van Erk

Thanks, Sebastian

I’ll set Mozilla as default (it seems to be the most common app, present in almost all distributions).

:slight_smile:

sebster:
Best thing to do is ask them what application they want to open the file, and possibly substitute %s with the filename. Once they’ve answered this question once, remember it.

For example, on my unix install, images could be displayed with a variety of programs:

gimp %s
mozilla %s
firefox %s
xv %s
display %s

Personally I prefer xv or mozilla. Others prefer firefox.

Also you can do all kinds of options this way, for example:

myprogram --filename %s --myotheroption someothervalue

Sebastiaan van Erk

[/quote]

I tried with several combinations, but I’ve only been able to make this one work:
application.executeProgram(‘mozilla’, tmpfile);

But, this way, Mozilla must be closed in order to come back to Servoy.
Is it possible to make Mozilla act as a non-modal window?