Saving file to client location

Using Servoy to administrate the content of your website? Discuss all webrelated Servoy topics on this forum!

Saving file to client location

Postby derk.hulshof » Mon Jun 23, 2014 3:07 pm

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
derk.hulshof
 
Posts: 87
Joined: Tue Dec 03, 2013 9:18 am
Location: Netherlands

Re: Saving file to client location

Postby Harjo » Mon Jun 23, 2014 4:37 pm

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
Harjo Kompagnie
Direct ICT / Servoy Hosting / ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
User avatar
Harjo
 
Posts: 4269
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Saving file to client location

Postby derk.hulshof » Tue Jun 24, 2014 9:18 am

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
derk.hulshof
 
Posts: 87
Joined: Tue Dec 03, 2013 9:18 am
Location: Netherlands

Re: Saving file to client location

Postby derk.hulshof » Tue Jun 24, 2014 9:25 am

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')
}
derk.hulshof
 
Posts: 87
Joined: Tue Dec 03, 2013 9:18 am
Location: Netherlands

Re: Saving file to client location

Postby Harjo » Tue Jun 24, 2014 9:41 am

strange way of reading a file as bytes!

just use: plugins.file.readFile......
Harjo Kompagnie
Direct ICT / Servoy Hosting / ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
User avatar
Harjo
 
Posts: 4269
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Saving file to client location

Postby derk.hulshof » Tue Jun 24, 2014 9:47 am

Everything works fine now.. tnx Harjo for the advice
derk.hulshof
 
Posts: 87
Joined: Tue Dec 03, 2013 9:18 am
Location: Netherlands


Return to Web Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron