Write File to Server

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

/**
 * @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)

}

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.pearce:
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.

Is there also a way to upload files to the server through a byte array? Instead of a file on disk?