Write File to Server

Questions and answers on developing, deploying and using plugins and JavaBeans

Write File to Server

Postby david.pearce » Wed Jun 04, 2014 6:56 pm

Hi,

I am wanting to write a file to the server, but pause until it is written, so I can check it is 100% there before the user moves on.
Using the streaming file write function i can get this to work, but it is asynchronous, so I would prefer to use the it2be plugin so i mark the app as busy until written, read its size or something to flag to the user a file of Xmb was written.

The only issue is I cannot appear to get the simple writeFile routing to work.

I have a byte array passed to my script. I even tried to write it to a local file and then read the bytes.

When i pass it to the plugin, it saves a file of 10k with an array in it like '@123bd3'

I must be doing something stupid, as I am sure this plugin must work!

plugins.it2be_tools.server().writeFile(_dir + 'test.pdf',_file)

whether I use _file (which is a good pdf byte array passed to the script) or read for f.getBytes()

it writes a file but as above just puts an array in the file not the file!

I attach the code I am using semi-successfully as this only works with the file streaming plugin not the it2be one.

If anyone has any sample code they use, I would be grateful for it. Just one of those where i am banging my head against a brick wall

David

Code: Select all
/**
* @param {JSRecord<db:/reportwriter/so_records>||JSRecord<db:/practicemanager/printq>} _record
* @param {Array<byte>} _file
* @param {Boolean} [_del]
* @properties={typeid:24,uuid:"1CB0A355-5D78-469B-93C7-E71CE56159F2"}
*
*/
function write_file(_record, _file, _del) {

   var _id = _record.id
   var _type = _record.filetype
   var _filename = _record.id.toString()
   var _table = databaseManager.getDataSourceTableName(_record.foundset.getDataSource())

   // Create the JSFile instance based on the file name.
   var oldfile;
   var f = plugins.file.createTempFile('myfile', '.' + _type);

   if (!plugins.file.writeFile(f, _file))
      application.output('Failed to write the file.');
   application.output(f.getAbsolutePath())
   if (_id) {
      /* @type {String} */
      var _idstr = _id.toString()
      var _length = _idstr.length
      var _dir;
      if (_del == true) {
         oldfile = _filename
         _filename = 'DEL_' + _filename
      }
      _dir = getDir(_id, _table)

   }
   //   _dir = plugins.file.getDefaultUploadLocation() + _dir
   //   application.output(_dir + '--' + _filename + '--' + f.getBytes())
   //   plugins.it2be_tools.server().createDirectory(_dir)
   //   plugins.it2be_tools.server().writeFile(_dir + _filename + '.' + _type, _file)

   plugins.file.streamFilesToServer(f, _dir + _filename + '.' + _type)

   if (_del == true) {
      _dir = plugins.file.getDefaultUploadLocation() + _dir
      plugins.it2be_tools.server().deleteFile(_dir + oldfile + '.' + _type)
   }

   //plugins.file.streamFilesToServer(f, _dir + _filename + '.' + _type, uploadCallback)

}
david.pearce
 
Posts: 36
Joined: Thu Jan 31, 2013 11:21 am

Re: Write File to Server

Postby david » Wed Jun 04, 2014 8:01 pm

I would stick with the streaming/async approach. Use the busy plugin to block the UI when the process starts and in the streaming callback method release the UI block.
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1724
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Write File to Server

Postby mboegem » Thu Jun 05, 2014 1:01 am

david.pearce wrote:Using the streaming file write function i can get this to work, but it is asynchronous, so I would prefer to use the it2be plugin so i mark the app as busy until written


I have no experience with the IT2Be stream files to server functionality, I always use the Usermanager plugin to stream files to server.
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1386
Joined: Sun Oct 14, 2007 1:34 pm
Location: Hoofddorp, The Netherlands

Re: Write File to Server

Postby jesse » Fri Oct 13, 2017 7:57 pm

Is there also a way to upload files to the server through a byte array? Instead of a file on disk?
jesse
 
Posts: 8
Joined: Tue Sep 01, 2015 12:12 pm


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 1 guest