# Open/Save file from web client

**URL:** <https://forum.servoy.com/t/open-save-file-from-web-client/6862>\
**Category:** Classic Servoy\
**Created:** [December 14, 2006, 4:43pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862 "2006-12-14T16:43:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dexadrine](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@Dexadrine](https://forum.servoy.com/u/Dexadrine)\
**Post date:** [December 14, 2006, 4:43pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/1 "2006-12-14T16:43:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Riccardino](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@Riccardino](https://forum.servoy.com/u/Riccardino)\
**Post date:** [December 14, 2006, 5:51pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/2 "2006-12-14T17:51:45Z")

</div>

> 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

Isn’t it default media field behaviour?

---

<div class="post-metadata">

**Author:** ![Dexadrine](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@Dexadrine](https://forum.servoy.com/u/Dexadrine)\
**Post date:** [December 15, 2006, 8:53am UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/3 "2006-12-15T08:53:19Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![Riccardino](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@Riccardino](https://forum.servoy.com/u/Riccardino)\
**Post date:** [December 15, 2006, 12:05pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/4 "2006-12-15T12:05:20Z")

</div>

> Dexadrine:
> 
> > 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.

---

<div class="post-metadata">

**Author:** ![Dexadrine](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@Dexadrine](https://forum.servoy.com/u/Dexadrine)\
**Post date:** [December 18, 2006, 2:11pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/5 "2006-12-18T14:11:07Z")

</div>

OK here’s what I have so far:

Script 1:  
I create a dataset and do the following:

```auto
//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:

```auto
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.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [December 20, 2006, 3:10pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/6 "2006-12-20T15:10:44Z")

</div>

Remember - the WEB client - you’re in a browser.

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.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Westy](https://avatars.discourse-cdn.com/v4/letter/w/9de053/32.png) [@Westy](https://forum.servoy.com/u/Westy)\
**Post date:** [December 20, 2006, 6:53pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/7 "2006-12-20T18:53:21Z")

</div>

> 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.

Dean

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [December 21, 2006, 8:45am UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/8 "2006-12-21T08:45:21Z")

</div>

You can use the blobloader and stream files from the database or a global media field to the (web)client.

Paul

---

<div class="post-metadata">

**Author:** ![Dexadrine](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@Dexadrine](https://forum.servoy.com/u/Dexadrine)\
**Post date:** [December 21, 2006, 8:49am UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/9 "2006-12-21T08:49:48Z")

</div>

Thanks guys,

I cracked it a couple of days ago with this:

```auto
//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);

```

---

<div class="post-metadata">

**Author:** ![Dexadrine](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@Dexadrine](https://forum.servoy.com/u/Dexadrine)\
**Post date:** [December 21, 2006, 8:51am UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/10 "2006-12-21T08:51:42Z")

</div>

> pbakker:  
> You can use the blobloader and stream files from the database or a global media field to the (web)client.
> 
> Paul

Whats the blobloader?

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [December 21, 2006, 8:51am UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/11 "2006-12-21T08:51:53Z")

</div>

Make sure that you don’t fill up the server with all the export files users create ![:-)]( "Smile")

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [December 21, 2006, 9:40am UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/12 "2006-12-21T09:40:54Z")

</div>

Search the forum, I’d say… ![:D]( "Very Happy")

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.

```auto
var URL = 'media:///servoy_blobloader?servername=' + currentcontroller.getServerName() + '&tablename=XXXXX&dataprovider=YYYYY&rowid1=' + ZZZZZ+'&mimetype='+AAAAA+'&filename='+BBBBBB
	return '<html><body><a target="_blank" href="'+URL+'">test</a></body></html>';

```

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

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [December 21, 2006, 2:08pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/13 "2006-12-21T14:08:53Z")

</div>

If you’re using Web Client then you don’t have to do any of that coding at all.

Just use:

controller.printPreview()

On the Smart Client it will go into print preview, when you’re viewing your solution on the web SERVOY will automatically create a PDF for you.

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [December 21, 2006, 2:11pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/14 "2006-12-21T14:11:15Z")

</div>

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.

Paul

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [December 21, 2006, 2:13pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/15 "2006-12-21T14:13:22Z")

</div>

Paul, I 100% agree with you. GREAT code sample!

---

<div class="post-metadata">

**Author:** ![Westy](https://avatars.discourse-cdn.com/v4/letter/w/9de053/32.png) [@Westy](https://forum.servoy.com/u/Westy)\
**Post date:** [December 21, 2006, 2:34pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/16 "2006-12-21T14:34:01Z")

</div>

> 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!

Dean

---

<div class="post-metadata">

**Author:** ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)\
**Post date:** [June 9, 2008, 1:06pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/17 "2008-06-09T13:06:04Z")

</div>

Can someone see what is wrong with the following line.  
I think I do like expected, but for some reason I don’t see the correct image:

This is my code:

```auto
if (_to_webshop.button_image_add_to_cart)
	elements.btn_add_to_cart.setImageURL('media:///servoy_blobloader?servername='+ _to_webshop.getServerName()+'&tablename='+ _to_webshop.getTableName()+'&dataprovider=button_image_add_to_cart&webshop_id=' + _to_webshop.webshop_id + '&mimetype=image/png');

```

The relation \_to\_webshop points to 1 single record.  
When I do \_to\_webshop.getSize() I get 1 as result

I’ve put the same line as application.output and I see the following:

```auto
media:///servoy_blobloader?servername=myServer&tablename=webshop&dataprovider=button_image_add_to_cart&webshop_id=f7fb71a2-b8fb-4b97-9a17-087042dd642b&mimetype=image/png

```

That looks correct. It is also the correct webshop\_id

But the image I see is from another record (first record) in the webshop table.

I also tried to replace ‘webshop\_id=’ by ‘rowid1=’, but that doesn’t change anything.

Does someone see in the coding line what is wrong?

---

<div class="post-metadata">

**Author:** ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)\
**Post date:** [June 9, 2008, 2:55pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/18 "2008-06-09T14:55:51Z")

</div>

I tried all kind of combinations.

The following is working:

```auto
elements.btn_add_to_cart.setImageURL('media:///servoy_blobloader?servername='+ _to_webshop.getServerName()+'&tablename='+ _to_webshop.getTableName()+'&dataprovider=button_image_add_to_cart&rowid1=' + _to_webshop.webshop_id + '&mimetype=image/png');

```

Important is also not to put double quotes around the value (so not rowid1=“f7fb71a2-b8fb-4b97-9a17-087042dd642b”, which I tried before)

Wouldn’t it be more logic to use the real columnname in stead of rowid1?

---

<div class="post-metadata">

**Author:** ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)\
**Post date:** [June 10, 2008, 9:02am UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/19 "2008-06-10T09:02:51Z")

</div>

Unfortunately I was too early happy.

It works perfect in Smart client but not at all in webclient

I made an example solution.  
I hope that Support can see what is wrong

Martin

---

<div class="post-metadata">

**Author:** ![Westy](https://avatars.discourse-cdn.com/v4/letter/w/9de053/32.png) [@Westy](https://forum.servoy.com/u/Westy)\
**Post date:** [October 8, 2008, 5:35pm UTC](https://forum.servoy.com/t/open-save-file-from-web-client/6862/20 "2008-10-08T17:35:04Z")

</div>

> pbakker:  
> Search the forum, I’d say… ![:D]( "Very Happy")
> 
> 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.
> 
> ```auto
> var URL = 'media:///servoy_blobloader?servername=' + currentcontroller.getServerName() + '&tablename=XXXXX&dataprovider=YYYYY&rowid1=' + ZZZZZ+'&mimetype='+AAAAA+'&filename='+BBBBBB
> 
> ```

```
return '<html><body><a target="_blank" href="'+URL+'">test</a></body></html>';

```

> ```auto
> 
> 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.

Dean Westover  
Choices Software, Inc.

[Next page](https://forum.servoy.com/t/open-save-file-from-web-client/6862.md?page=2)
