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

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

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

Postby Harjo » Wed Dec 24, 2003 2:58 pm

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:
Code: Select all
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:

Code: Select all
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.
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Postby david » Mon Dec 29, 2003 5:13 pm

Tack this onto the end for Mac:

Code: Select all
else
{
if (utils.stringLeftWords(application.getOSName(), 1) == "Mac")
{
   application.executeProgram('open', filename);
}
}


- david
Last edited by david on Mon Dec 29, 2003 5:34 pm, edited 1 time in total.
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Postby Bert » Mon Dec 29, 2003 5:31 pm

david wrote:Tack this onto the end for Mac:


Thank You, David :D
Bert de Graaff
ATB Software Servoy Developer manage your business anywhere
User avatar
Bert
 
Posts: 201
Joined: Tue May 20, 2003 11:16 am
Location: Stramproy - NL

Linux: open with default app

Postby Riccardino » Fri Aug 27, 2004 3:45 pm

david wrote:Tack this onto the end for Mac:

Code: Select all
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).
ciao, ric
User avatar
Riccardino
 
Posts: 911
Joined: Thu Apr 24, 2003 11:42 am
Location: Ferrara, Italy

Postby sebster » Fri Sep 03, 2004 2:24 pm

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
Sebastiaan van Erk
Servoy
sebster
 
Posts: 251
Joined: Thu Apr 24, 2003 10:03 am
Location: Utrecht, The Netherlands

Postby Riccardino » Wed Sep 08, 2004 2:46 pm

sebster wrote: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).

:-)
ciao, ric
User avatar
Riccardino
 
Posts: 911
Joined: Thu Apr 24, 2003 11:42 am
Location: Ferrara, Italy

Postby Riccardino » Sat Sep 11, 2004 11:06 am

sebster wrote: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?
ciao, ric
User avatar
Riccardino
 
Posts: 911
Joined: Thu Apr 24, 2003 11:42 am
Location: Ferrara, Italy


Return to How To

Who is online

Users browsing this forum: No registered users and 3 guests