I am developing a web client based solution and would like the ability to save/export a file from the servoy window in the browser (like downloading a file from a website).
The files will be csv and pdf format, generated from scripts.
Can this be done? If so, could someone give me some pointers?
Dexadrine:
I am developing a web client based solution and would like the ability to save/export a file from the servoy window in the browser (like downloading a file from a website).
The files will be csv and pdf format, generated from scripts.
Can this be done? If so, could someone give me some pointers?
Riccardino:
Isn’t it default media field behaviour?
Care to elaborate?
In the smart client, to export a csv i would write a method to open the save file dialog (so that the user can choose the location) and write the text file to that location, fairly simple. I am slightly baffled with how to recreate this type of thing in the web client.
Riccardino:
Isn’t it default media field behaviour?
Care to elaborate?
In the smart client, to export a csv i would write a method to open the save file dialog (so that the user can choose the location) and write the text file to that location, fairly simple. I am slightly baffled with how to recreate this type of thing in the web client.
If you store your file in a media field, then you can let the user download it in his chosen location.
Script 1:
I create a dataset and do the following:
//create a csv from the dataset
var csv = dataset.getAsText(',','\n','"',true);
//create the temp csv and store it in the media field for downloading
var tempFile = plugins.file.createTempFile('report','.csv');
var success = plugins.file.writeTXTFile(tempFile,csv);
if(success) {globals.g_csvfile = tempFile;}
I have a button with the following:
Script2:
application.showURL(globals.g_csvfile,'_blank');
This works in smart client (opens the csv file), but not in web client, it opens the “install smart client” page.
Browser = “dumb” application that draws HTML from a server.
In the Smart Client you’re running Java on the local client.
Java Client = “smart” client that can interact with the local file system, etc.
It works in Smart Client because the file is downloaded to the local machine. Using the Web Client, the “client” is running on the SERVER and not the local machine, so the file isn’t downloaded to the local machine, therefore it can’t be opened.
Dexadrine:
I am developing a web client based solution and would like the ability to save/export a file from the servoy window in the browser (like downloading a file from a website).
The files will be csv and pdf format, generated from scripts.
Can this be done? If so, could someone give me some pointers?
Thanks
When a PDF opens within a browser you can click the disk icon that is located in the upper lefter corner of the screen (just above the pdf) to download and save.
With the csv I believe you can write it to the built-in Tomcat web server ROOT folder or subfolder and then pass back a link to that file that can be right-clicked (on Windows platform) and saved locally.
//create a csv from the dataset
var csv = dataset.getAsText(',','\n','"',true);
//create the temp csv and store it for downloading
var fileName = 'report.csv';
var tempFile = './server/webapps/ROOT/' + fileName;
var success = plugins.file.writeTXTFile(tempFile,csv);
But with the BlobLoader you can extract files from the DB or globals and use them in the same way as you would use files from Servoys media library inside HTML.
In the latest 3.1 beta’s more functionality has been added, so if you have a global containing a file, you can use that as well, you can set the mime-type and filename as well.
for example, if you create a calculation with the following code, and place a HTML Area on your form with the Calc as DataProvider, then, in the WebClient, clicking the link would open the file.
Well, if you’d like to print, that’s the best, but if I want to open a word file, an Image, CSV file or any other file in their native editor, I think this is the way to go.
pbakker:
In the latest 3.1 beta’s more functionality has been added, so if you have a global containing a file, you can use that as well, you can set the mime-type and filename as well.
Thank you for pointing this out and for the nice example of this great new feature!
But with the BlobLoader you can extract files from the DB or globals and use them in the same way as you would use files from Servoys media library inside HTML.
In the latest 3.1 beta’s more functionality has been added, so if you have a global containing a file, you can use that as well, you can set the mime-type and filename as well.
for example, if you create a calculation with the following code, and place a HTML Area on your form with the Calc as DataProvider, then, in the WebClient, clicking the link would open the file.
var URL = 'media:///servoy_blobloader?servername=' + currentcontroller.getServerName() + '&tablename=XXXXX&dataprovider=YYYYY&rowid1=' + ZZZZZ+'&mimetype='+AAAAA+'&filename='+BBBBBB
Where:
- XXXXX is the name of the table your file is stored in
- YYYYYY is the columnname of the column where the file is stored
- ZZZZZ is value of the PK field of the row (In case of a PK buildup out of multiple columns, add &rowid2=value ... &rowidXX=value)
- AAAAA is the mimetype of the file
- BBBBB is the name of the file
Regards,
Paul
What is the syntax for using with a global media field?
What is the syntax for using with a application.showURL?
The above example worked perfectly, but I am having trouble getting it to work while using with a global and with show URL.