Some examples have been requested on how to use this. Here are a few…
Example #1:
Copy a file from the client to the App Server (file paths are in mac format).
plugins.dialogs.showInfoDialog( "", "Please choose the File to copy", "OK")
var clientTemp = plugins.file.showFileOpenDialog()
if(clientTemp)
{
//a path on the App Server
var serverLoc = "/Users/admin/Desktop/" + clientTemp.getName();
var success = plugins.DDC_FileStream.copyFileFromClientToAppServer(clientTemp, serverLoc, 1024)
if(success == "true")
{
//watever you want
}
else
{
plugins.dialogs.showInfoDialog( "ERROR", success + "\n" + serverLoc, "ok")
}
}
Example #2:
Copy a file from the Appserver into the database, and open it on the client’s machine in the default program…
First, some module methods:
Method Name: mod_filestr_insertIntoDBFromAppSvrAndViewFile
/******************************************
SB 7/13/06
App Server streams file from local into database, and the
Client openes the file on their machine (temp file).
If the file already exists, it is just opened.
Parameters:
[0] - fileName (String)
[1] - fileType (ENUM('case_report'))
[2] - serverName (String)
[3] - tableName (String)
[4] - serverFileLocation (String)
[5] - preparedStatement (String)
Returns:
fileName of tempFile
******************************************/
var fileName = arguments[0];
var fileType = arguments[1];
var serverName = arguments[2];
var tableName = arguments[3];
var serverFileLocation = arguments[4];
var preparedStatement = arguments[5];
//Check to see if file is in the DB already
//forms.tbl_file.controller.show()
forms.tbl_file.controller.find()
forms.tbl_file.fle_name = fileName
forms.tbl_file.fle_type = fileType
var count = forms.tbl_file.controller.search()
if(count > 0)
{
//File exists, so don't insert it again.
var success = "true"
}
else
{
//File doesn't exist in the database, so tell the app server to insert it
var success = plugins.DDC_FileStream.copyFileFromAppServerToDB(serverFileLocation, serverName, tableName, preparedStatement)
}
//create file from BLOB and load to user
if(success == "true")
{
var a = fileName.lastIndexOf(".")
var b = fileName.substr(0,a)
var c = fileName.substring(a)
var newFile = application.createTempFile(b,c)
forms.tbl_file.controller.find()
forms.tbl_file.fle_name = fileName
forms.tbl_file.fle_type = fileType
forms.tbl_file.controller.search()
application.writeFile(newFile, forms.tbl_file.fle_file);
globals.mod_utils_openFileExternal(newFile);
}
else
{
plugins.dialogs.showInfoDialog( "ERROR", success + "\n" + serverFileLocation, "ok")
}
Method Name: mod_utils_openFileExternal
/******************************************
SB 5/22/06
Opens file in default application
Parameters:
[0] - filename (String)
Returns:
NA
******************************************/
var filename = arguments[0];
if(globals.mod_util_isMacOS())
{
application.executeProgram('open', filename);
}
else
{
application.executeProgramInBackground('rundll32', 'url.dll,FileProtocolHandler',filename)
}
Method Name: mod_util_isMacOS
/******************************************
SB 5/2/06
Returns boolean of OS = Mac. True if Mac. False if Windoze
Parameters:
NA
Returns:
boolean
******************************************/
if(utils.stringMiddle(application.getOSName(),1,7) == "Windows")
{
return false
}
else
{
return true
}
And Finally, the main method that calls the methods in the modules…
var clientTemp = plugins.it2be_tools.client().tempDir
if(globals.mod_util_isMacOS())
{
clientTemp += "/" + fle_fileid + ".pdf"
}
else
{
clientTemp += "\\" + fle_fileid + ".pdf"
}
var serverLoc = "/Volumes/scans-case/" + fle_folder + "/" + fle_fileid + ".pdf";
var preparedStatement = "insert into file values(\"" + fle_fileid + ".pdf\", \"case_report\", \"" + plugins.it2be_tools.client().MACAddress + "\",?)"
globals.mod_filestr_insertIntoDBFromAppSvrAndViewFile(fle_fileid + ".pdf", "case_report", "misc", "file", serverLoc, preparedStatement);
The prepared statement is based on a file table we have that holds a fileID, useMacAddress, and a BLOB for the file.