Can't find method com.servoy.extensions.plugins.file.WebFile

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Can't find method com.servoy.extensions.plugins.file.WebFile

Postby swingman » Sun Aug 21, 2022 1:02 pm

Hi all,

I'm grabbing an attachment from Outlook in NG-client 2021.12.
Then I save this to disk before posting the attachment to cloud storage using the HTTP plugin.

When deploying to a Tomcat server, and running Servoy as an Outlook Add-In (this is done in an iFrame), writing to the file fails and I get the following message:

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

Code: Select all
/**
* @properties={typeid:24,uuid:"94BC16CB-F770-4CD8-890B-0F96D5F1B156"}
* @param {String} upload_filename
* @param {Array<byte>} uploaded_data
* @return {String}
*/
function write_file(upload_filename, uploaded_data) {
   var root = upload_filename;
   var extension = '.' + root.split('.').pop();
   var file = plugins.file.createTempFile(root, extension);

   if (plugins.file.writeFile(file, uploaded_data)) {
      return file.getAbsolutePath();
   } else {
      return null;
   }

}


Maybe Servoy is trying to save the file on the client computer rather than on the server.
Any idea of how to get around this?
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1472
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Re: Can't find method com.servoy.extensions.plugins.file.Web

Postby jcompagner » Sun Aug 21, 2022 4:33 pm

the thing is that uploaded_data is not a byte[] (even if you say that in that method) but it really is a string and there is no such method (file, string)
there is a writeTXTFile(file,string)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Can't find method com.servoy.extensions.plugins.file.Web

Postby swingman » Sun Aug 21, 2022 4:43 pm

Thanks, I will try that now.

Since the data comes from outlook via the Outlook plugin, I'm not 100% sure what it is. I assumed it was binary data of some kind.
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1472
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Re: Can't find method com.servoy.extensions.plugins.file.Web

Postby swingman » Mon Aug 22, 2022 2:32 pm

If I change the code to use writeTXTFile and try to read the file back from cloud storage Excel and Word say the files are corrupted.

Modifying using some test code that jasantana write for me, I came up with this version:
Code: Select all
/**
* @properties={typeid:24,uuid:"94BC16CB-F770-4CD8-890B-0F96D5F1B156"}
* @param {String} upload_filename
* @param {String} uploaded_data
* @return {String}
*/
function write_file(upload_filename, uploaded_data) {
   var root = upload_filename;
   var extension = '.' + root.split('.').pop();
   var file = plugins.file.createTempFile(root, extension);

   var bytesContent = utils.base64ToBytes(uploaded_data);

   if (file.setBytes(bytesContent, true)) {
      return file.getAbsolutePath();
   } else {
      return null;
   }

}


Excel and Word can now read the files.
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1472
Joined: Wed Oct 01, 2003 10:20 am
Location: London


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 16 guests