Page 1 of 1

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

PostPosted: Sun Aug 21, 2022 1:02 pm
by swingman
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?

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

PostPosted: Sun Aug 21, 2022 4:33 pm
by jcompagner
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)

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

PostPosted: Sun Aug 21, 2022 4:43 pm
by swingman
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.

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

PostPosted: Mon Aug 22, 2022 2:32 pm
by swingman
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.