Hi
Am using the file plugin to stream files to the server and renaming them with the primary key (because of versioning) from a table using code
if (vPath)
{
var new_name = "/" + vID + vFiletype;
plugins.file.streamFilesToServer(vPath, new_name);
}
this works perfectly as per the tool tip allowing me to rename the file and saving the file in the default server directory .
I want to do the same thing using ‘streamFilesFromServer’ (to change the filename back to its original) and as per the tooltip
plugins.file.streamFilesFromServer(file/fileName|fileArray/fileNameArray, serverFile/serverFileName|serverFileArray/serverFileNameArray, [Function callbackFunction])
this should be possible. The samplecode however is different as:
// transfer all the files of a chosen server folder to a directory on the client
var dir = plugins.file.showDirectorySelectDialog();
if (dir)
{
var list = plugins.file.getRemoteFolderContents('/images/user1/', null, 1);
if (list)
{
var monitor = plugins.file.streamFilesFromServer(dir, list, callbackFunction);
}
}
and there doesn’t seem to be a way that i can rename the file as it is done in ‘streamFilesToServer’. Am i missing something? Is this possible? What is the best way to rename the file during or after it is streamed?
Any help would be appreciated.
You can certainly rename files using streamFilesFromServer.
You can do it with one file or an array of files like in the following example:
// transfer all the files of a chosen server folder to a directory on the client
var dir = plugins.file.showDirectorySelectDialog();
if (dir)
{
var list = plugins.file.getRemoteFolderContents('/images/user1/', null, 1);
if (list)
{
var clientFiles = new Array();
for (var i = 0; i < list.length; i++)
{
// you will have implement your own renaming scheme of course... here, I just set the name to (i+1) + extension
var extension = getExtension(list[i].getName());
var newName = (i+1) + "." + extension;
// create the new JSFile which will receive the data, setting its new name:
var f = plugins.file.createFile(dir.getAbsolutePath() + "/" + newName);
// put that in the array (in the same order as the remote files):
clientFiles.push(f);
}
// then use this array as first argument:
var monitor = plugins.file.streamFilesFromServer(clientFiles, list, callbackFunction);
//...
}
}
// inner extract extension function:
function getExtension(name) {
if (name) {
var tokens = name.split("\.");
return tokens[tokens.length - 1];
}
return name;
}
You cannot (yet) use renameTo() on a remote JSFile the way you can on a local JSFile.
Will look at implementing that soon…
Hope this helps,
Hi Patrick
Thanks for the help, all working fine.
Am writing the file now back to a temp directory and automatically opening with the default program.