Page 1 of 1

Saving file to client location

PostPosted: Mon Jun 23, 2014 3:07 pm
by derk.hulshof
Hi all,

I have build a web application, where the it2be word plugin is generating a word document.

Now I want the user/client to choose the save location.
plugins.file.showFileSaveDialog = not web enabled getting headles exception errors.

plugins.it2be_word.save('c:/test.docx') = saving to the server c: drive

plugins.it2be_word.save(plugins.file.showFileSaveDialog(plugins.file.getDesktopFolder())) = working but only from a local servoy instance.

Any help is welcome.
Tnx in advance

Derk

Servoy 7.3.1
Java v7

Re: Saving file to client location

PostPosted: Mon Jun 23, 2014 4:37 pm
by Harjo
You cant save a file directly to local drive of a user using webclient. You can do plugins.file.writeFile.... so the file will present as a download

Re: Saving file to client location

PostPosted: Tue Jun 24, 2014 9:18 am
by derk.hulshof
Hi Harjo,
Tnx for the reply. I have tried 2 things but only got errors.

1 .
I have tried the writeFile method
writeFile('report.docx', plugins.it2be-word.documentobject)
I got the following error.
Can't find method com.servoy.extensions.plugins.file.WebFileProvider.js_writeFile(string,com.it2be.word.IWDocument,string).

2.
When I let the it2be plugin save the document first to
var _savelocation = '../application_server/w_docs/report.docx';
_document.save( _savelocation);
Then I added a download button with the following code:
var _pathto = "../application_server/w_docs/";
var _repname = 'report.docx';
var _reportfilename = _pathto + _repname;
var _f = plugins.file.convertToJSFile(_reportfilename)
if(_f && _f.canRead()){
plugins.file.writeFile('report.docx', _f , 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
} else {
application.output('cant read file')
}

Error: Can't find method com.servoy.extensions.plugins.file.WebFileProvider.js_writeFile(string,com.servoy.extensions.plugins.file.JSFile,string)

Think I am missing something here, or just having a bad day :D

Re: Saving file to client location

PostPosted: Tue Jun 24, 2014 9:25 am
by derk.hulshof
got it:

I mixed up that the file wasnt read as bytes. Instead of making a byte array.

Tnx for the advice

Working code example:
var bytes = new Array();
for (var i=0; i<10240; i++)
bytes[i] = i % 100;

var _pathto = "../application_server/w_docs/";
var _repname = 'report.docx';
var _reportfilename = _pathto + _repname;
var _f = plugins.file.convertToJSFile(_reportfilename)
if(_f && _f.canRead()){
plugins.file.writeFile('report.docx', bytes , 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
} else {
application.output('cant read file')
}

Re: Saving file to client location

PostPosted: Tue Jun 24, 2014 9:41 am
by Harjo
strange way of reading a file as bytes!

just use: plugins.file.readFile......

Re: Saving file to client location

PostPosted: Tue Jun 24, 2014 9:47 am
by derk.hulshof
Everything works fine now.. tnx Harjo for the advice