file
(plugins.file)
Overview
The file management plugin offers a comprehensive toolkit for managing files and folders both locally and remotely. It supports operations such as creating, reading, modifying, and deleting files while accommodating various formats, including text, binary, and XML. Advanced features like encoding, content streaming, and size management are also integrated to enhance file interactions on both the client and server sides.
Users can perform essential tasks such as appendToTXTFile
, writeFile
, and writeXMLFile
, which allow appending, creating, or modifying files efficiently. The plugin also supports creating temporary files through createTempFile
and managing folder contents with getFolderContents
. Folder operations include recursive copying using copyFolder
and deletion with deleteFolder
, all while providing detailed file attributes such as modification dates via getModificationDate
and sizes with getFileSize
. Flexible filtering options enable targeted retrieval of folder contents, enhancing workflow precision.
For interactive use, the plugin facilitates file selection dialogs through showFileOpenDialog
, supporting multiselect and file type filters, with customizable callback functionality. Large files can be streamed directly to the browser using streamFile
without consuming excessive memory, ensuring optimal performance for downloads or inline viewing. Temporary file handling via trackFileForDeletion
automates cleanup processes upon solution closure, contributing to resource efficiency.
Properties
servoy.FileServerService.defaultFolder
Set the default folder path (absolute path on the server) to save files sent by clients (will default to user.home/.servoy/uploads/UUID/)
Returned Types
Methods Summarized
Appends a string given in parameter to a file, using default platform encoding.
Appends a string given in parameter to a file, using the specified encoding.
Appends a string given in parameter to a file, using default platform encoding.
Appends a string given in parameter to a file, using the specified encoding.
Returns a JSFile instance corresponding to an alternative representation of a file (for example a string).
Convenience return to get a JSFile representation of a server file based on its path.
Copies the sourcefolder to the destination folder, recursively.
Creates the folder by the given pathname, including any necessary but nonexistent parent folders.
Returns an Array of JSFile instances correponding to the file system root folders.
Returns an array of JSFile instances corresponding to content of the specified folder.
Returns an array of JSFile instances corresponding to content of the specified folder.
Returns an array of JSFile instances corresponding to content of the specified folder.
Returns an array of JSFile instances corresponding to content of the specified folder.
Returns an array of JSFile instances corresponding to content of the specified folder.
Returns an array of JSFile instances corresponding to content of the specified folder.
Returns an array of JSFile instances corresponding to content of the specified folder.
Returns an array of JSFile instances corresponding to content of the specified folder.
Returns an array of JSFile instances corresponding to content of the specified folder.
Returns an array of JSFile instances corresponding to content of the specified folder.
Returns a JSFile instance corresponding to the home folder of the logged in used.
Returns an array of JSFile instances corresponding to content of the specified folder on the server side.
Returns an array of JSFile instances corresponding to content of the specified folder on the server side.
Returns an array of JSFile instances corresponding to content of the specified folder on the server side.
Returns an array of JSFile instances corresponding to content of the specified folder on the server side.
Returns an array of JSFile instances corresponding to content of the specified folder on the server side.
Returns an array of JSFile instances corresponding to content of the specified folder on the server side.
Returns an array of JSFile instances corresponding to content of the specified folder on the server side.
Returns an array of JSFile instances corresponding to content of the specified folder on the server side.
Returns an array of JSFile instances corresponding to content of the specified folder on the server side.
Returns an array of JSFile instances corresponding to content of the specified folder on the server side.
Opens the given data as a file.
Shows a file open dialog.
Shows a file open dialog.
Shows a file open dialog.
Shows a file open dialog.
Shows a file open dialog.
Shows a file open dialog.
void
Stream the given file(path) to the browser with content-disposition:attachment This will not load in the file fully into memory but only stream it right from disk.
void
String the given file(path) to the browser you can provide the content disposition how this should be send (inline or as an attachment) This will not load in the file fully into memory but only stream it right from disk.
void
String the given file(path) to the browser you can provide the content disposition how this should be send (inline or as an attachment) This will not load in the file fully into memory but only stream it right from disk.
void
If the client's solution is closed, the file given to this method will be deleted.
Methods Detailed
appendToTXTFile(file, text)
Appends a string given in parameter to a file, using default platform encoding.
Parameters
Returns: Boolean true if appending worked
Sample
// append some text to a text file:
var ok = plugins.file.appendToTXTFile('myTextFile.txt', '\nMy fantastic new line of text\n');
appendToTXTFile(file, text, encoding)
Appends a string given in parameter to a file, using the specified encoding.
Parameters
JSFile file a local JSFile
String text the text to append to the file
String encoding the encoding to use
Returns: Boolean true if appending worked
Sample
// append some text to a text file:
var ok = plugins.file.appendToTXTFile('myTextFile.txt', '\nMy fantastic new line of text\n');
appendToTXTFile(file, text)
Appends a string given in parameter to a file, using default platform encoding.
Parameters
Returns: Boolean true if appending worked
Sample
// append some text to a text file:
var ok = plugins.file.appendToTXTFile('myTextFile.txt', '\nMy fantastic new line of text\n');
appendToTXTFile(file, text, encoding)
Appends a string given in parameter to a file, using the specified encoding.
Parameters
String file the file path as a String
String text the text to append to the file
String encoding the encoding to use
Returns: Boolean true if the text is successfully appended to the file located at the specified file path using the given encoding; false otherwise.
Sample
// append some text to a text file:
var ok = plugins.file.appendToTXTFile('myTextFile.txt', '\nMy fantastic new line of text\n');
convertToJSFile(file)
Returns a JSFile instance corresponding to an alternative representation of a file (for example a string).
Parameters
Object file ;
Returns: JSFile a JSFile instance corresponding to the given file representation, or null if conversion is not possible.
Sample
var f = plugins.file.convertToJSFile("story.txt");
if (f.canRead())
application.output("File can be read.");
convertToRemoteJSFile(path)
Convenience return to get a JSFile representation of a server file based on its path.
Parameters
String path the path representing a file on the server (should start with "/")
Returns: JSFile the JSFile
Sample
var f = plugins.file.convertToRemoteJSFile('/story.txt');
if (f && f.canRead())
application.output('File can be read.');
copyFile(source, destination)
Copies the source file to the destination file. Returns true if the copy succeeds, false if any error occurs.
Parameters
Returns: Boolean true if the file was copied successfully; false otherwise.
Sample
// Copy based on file names.
if (!plugins.file.copyFile("story.txt", "story.txt.copy"))
application.output("Copy failed.");
// Copy based on JSFile instances.
var f = plugins.file.createFile("story.txt");
var fcopy = plugins.file.createFile("story.txt.copy2");
if (!plugins.file.copyFile(f, fcopy))
application.output("Copy failed.");
copyFolder(source, destination)
Copies the sourcefolder to the destination folder, recursively. Returns true if the copy succeeds, false if any error occurs.
Parameters
Returns: Boolean true if the folder was copied successfully; false otherwise.
Sample
// Copy folder based on names.
if (!plugins.file.copyFolder("stories", "stories_copy"))
application.output("Folder copy failed.");
// Copy folder based on JSFile instances.
var d = plugins.file.createFile("stories");
var dcopy = plugins.file.createFile("stories_copy_2");
if (!plugins.file.copyFolder(d, dcopy))
application.output("Folder copy failed.");
createFile(targetFile)
Creates a JSFile instance. Does not create the file on disk.
Parameters
Object targetFile ;
Returns: JSFile a JSFile instance representing the specified target file.
Sample
// Create the JSFile instance based on the file name.
var f = plugins.file.createFile("newfile.txt");
// Create the file on disk.
if (!f.createNewFile())
application.output("The file could not be created.");
createFolder(destination)
Creates the folder by the given pathname, including any necessary but nonexistent parent folders. Note that if this operation fails it may have succeeded in creating some of the necessary parent folders. Will return true if it could make this folder or if the folder did already exist.
Parameters
Object destination ;
Returns: Boolean true if the folder was created successfully or already exists; false otherwise.
Sample
var d = plugins.file.convertToJSFile("newfolder");
if (!plugins.file.createFolder(d))
application.output("Folder could not be created.");
createTempFile(prefix, suffix)
Creates a temporary file on disk. A prefix and an extension are specified and they will be part of the file name.
Parameters
Returns: JSFile a JSFile instance representing the created temporary file.
Sample
var tempFile = plugins.file.createTempFile('myfile','.txt');
application.output('Temporary file created as: ' + tempFile.getAbsolutePath());
plugins.file.writeTXTFile(tempFile, 'abcdefg');
deleteFile(destination)
Removes a file from disk. Returns true on success, false otherwise.
Parameters
Object destination ;
Returns: Boolean true if the file was successfully deleted; false otherwise.
Sample
if (plugins.file.deleteFile('story.txt'))
application.output('File deleted.');
//In case the file to delete is a remote file:
var file = plugins.file.convertToRemoteJSFile('/story.txt');
plugins.file.deleteFile(file);
deleteFolder(destination, showWarning)
Deletes a folder from disk recursively. Returns true on success, false otherwise. If the second parameter is set to true, then a warning will be issued to the user before actually removing the folder.
Parameters
Returns: Boolean true if the file was successfully deleted; false otherwise.
Sample
if (plugins.file.deleteFolder('stories', true))
application.output('Folder deleted.');
//In case the file to delete is a remote folder:
plugins.file.deleteFolder(plugins.file.convertToRemoteJSFile('/stories'), true);
getDefaultUploadLocation()
Returns the default upload location path of the server.
Returns: String the location as canonical path
Sample
// get the (server-side) default upload location path:
var serverPath = plugins.file.getDefaultUploadLocation();
getDiskList()
Returns an Array of JSFile instances correponding to the file system root folders.
Returns: Array an array of JSFile instances representing the root folders of the file system.
Sample
var roots = plugins.file.getDiskList();
for (var i = 0; i < roots.length; i++)
application.output(roots[i].getAbsolutePath());
getFileSize(fileOrPath)
Returns the size of the specified file.
Parameters
Object fileOrPath can be a (remote) JSFile or a local file path
Returns: Number the size of the specified file in bytes, or -1 if the file is invalid.
Sample
var f = plugins.file.convertToJSFile('story.txt');
application.output('file size: ' + plugins.file.getFileSize(f));
//In case the file is remote, located on the server side inside the default upload folder:
var f = plugins.file.convertToRemoteJSFile('/story.txt');
application.output('file size: ' + plugins.file.getFileSize(f));
getFolderContents(targetFolder)
Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
JSFile targetFolder JSFile object.
Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.
Sample
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
application.output(files[i].getAbsolutePath());
getFolderContents(targetFolder, fileFilter)
Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.
Sample
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
application.output(files[i].getAbsolutePath());
getFolderContents(targetFolder, fileFilter, fileOption)
Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
JSFile targetFolder JSFile object.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.
Sample
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
application.output(files[i].getAbsolutePath());
getFolderContents(targetFolder, fileFilter, fileOption, visibleOption)
Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
JSFile targetFolder JSFile object.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Number visibleOption 1=visible, 2=nonvisible
Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.
Sample
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
application.output(files[i].getAbsolutePath());
getFolderContents(targetFolder, fileFilter, fileOption, visibleOption, lockedOption)
Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
JSFile targetFolder JSFile object.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Number visibleOption 1=visible, 2=nonvisible
Number lockedOption 1=locked, 2=nonlocked
Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.
Sample
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
application.output(files[i].getAbsolutePath());
getFolderContents(targetFolder)
Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
String targetFolder File path.
Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.
Sample
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
application.output(files[i].getAbsolutePath());
getFolderContents(targetFolder, fileFilter)
Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.
Sample
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
application.output(files[i].getAbsolutePath());
getFolderContents(targetFolder, fileFilter, fileOption)
Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
String targetFolder File path.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.
Sample
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
application.output(files[i].getAbsolutePath());
getFolderContents(targetFolder, fileFilter, fileOption, visibleOption)
Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
String targetFolder File path.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Number visibleOption 1=visible, 2=nonvisible
Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.
Sample
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
application.output(files[i].getAbsolutePath());
getFolderContents(targetFolder, fileFilter, fileOption, visibleOption, lockedOption)
Returns an array of JSFile instances corresponding to content of the specified folder. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
String targetFolder File path.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Number visibleOption 1=visible, 2=nonvisible
Number lockedOption 1=locked, 2=nonlocked
Returns: Array an array of JSFile instances representing the contents of the specified folder that match the given filters.
Sample
var files = plugins.file.getFolderContents('stories', '.txt');
for (var i=0; i<files.length; i++)
application.output(files[i].getAbsolutePath());
getHomeFolder()
Returns a JSFile instance corresponding to the home folder of the logged in used.
Returns: JSFile a JSFile instance representing the home folder of the currently logged-in user.
Sample
var d = plugins.file.getHomeFolder();
application.output('home folder: ' + d.getAbsolutePath());
getMaxUploadFileSize()
Returns the maximum allowed file size for uploads in KB. Defaults to servoy.webclient.maxuploadsize parameter from Admin page
Returns: Number the maximum file size in KB
Sample
// get the current maximum file size
var maxSize = plugins.file.getMaxUploadFileSize();
application.output("Maximum file size: " + maxSize + " KB");
getModificationDate(fileOrPath)
Returns the modification date of a file.
Parameters
Object fileOrPath can be a (remote) JSFile or a local file path
Returns: Date the last modification date of the specified file, or null if the file is invalid.
Sample
var f = plugins.file.convertToJSFile('story.txt');
application.output('last changed: ' + plugins.file.getModificationDate(f));
//In case the file is remote, located on the server side inside the default upload folder:
var f = plugins.file.convertToRemoteJSFile('/story.txt');
application.output('file size: ' + plugins.file.getModificationDate(f));
getRemoteFolderContents(targetFolder)
Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
JSFile targetFolder ;
Returns: Array the array of file names
Sample
// retrieves an array of files located on the server side inside the default upload folder:
var files = plugins.file.getRemoteFolderContents(plugins.file.convertToRemoteJSFile('/'), '.txt');
getRemoteFolderContents(targetFolder, fileFilter)
Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
JSFile targetFolder Folder as JSFile object.
Object fileFilter Filter or array of filters for files in folder.
Returns: Array the array of file names
Sample
// retrieves an array of files located on the server side inside the default upload folder:
var files = plugins.file.getRemoteFolderContents(plugins.file.convertToRemoteJSFile('/'), '.txt');
getRemoteFolderContents(targetFolder, fileFilter, fileOption)
Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
JSFile targetFolder Folder as JSFile object.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Returns: Array the array of file names
Sample
// retrieves an array of files located on the server side inside the default upload folder:
var files = plugins.file.getRemoteFolderContents(plugins.file.convertToRemoteJSFile('/'), '.txt');
getRemoteFolderContents(targetFolder, fileFilter, fileOption, visibleOption)
Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
JSFile targetFolder Folder as JSFile object.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Number visibleOption 1=visible, 2=nonvisible
Returns: Array the array of file names
Sample
// retrieves an array of files located on the server side inside the default upload folder:
var files = plugins.file.getRemoteFolderContents(plugins.file.convertToRemoteJSFile('/'), '.txt');
getRemoteFolderContents(targetFolder, fileFilter, fileOption, visibleOption, lockedOption)
Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
JSFile targetFolder Folder as JSFile object.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Number visibleOption 1=visible, 2=nonvisible
Number lockedOption 1=locked, 2=nonlocked
Returns: Array the array of file names
Sample
// retrieves an array of files located on the server side inside the default upload folder:
var files = plugins.file.getRemoteFolderContents(plugins.file.convertToRemoteJSFile('/'), '.txt');
getRemoteFolderContents(targetFolder)
Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
String targetFolder ;
Returns: Array the array of file names
Sample
// retrieves an array of files located on the server side inside the default upload folder:
var files = plugins.file.getRemoteFolderContents('/', '.txt');
getRemoteFolderContents(targetFolder, fileFilter)
Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
Returns: Array the array of file names
Sample
// retrieves an array of files located on the server side inside the default upload folder:
var files = plugins.file.getRemoteFolderContents('/', '.txt');
getRemoteFolderContents(targetFolder, fileFilter, fileOption)
Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
String targetFolder Folder path.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Returns: Array the array of file names
Sample
// retrieves an array of files located on the server side inside the default upload folder:
var files = plugins.file.getRemoteFolderContents('/', '.txt');
getRemoteFolderContents(targetFolder, fileFilter, fileOption, visibleOption)
Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
String targetFolder Folder path.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Number visibleOption 1=visible, 2=nonvisible
Returns: Array the array of file names
Sample
// retrieves an array of files located on the server side inside the default upload folder:
var files = plugins.file.getRemoteFolderContents('/', '.txt');
getRemoteFolderContents(targetFolder, fileFilter, fileOption, visibleOption, lockedOption)
Returns an array of JSFile instances corresponding to content of the specified folder on the server side. The content can be filtered by optional name filter(s), by type, by visibility and by lock status.
Parameters
String targetFolder Folder path.
Object fileFilter Filter or array of filters for files in folder.
Number fileOption 1=files, 2=dirs
Number visibleOption 1=visible, 2=nonvisible
Number lockedOption 1=locked, 2=nonlocked
Returns: Array the array of file names
Sample
// retrieves an array of files located on the server side inside the default upload folder:
var files = plugins.file.getRemoteFolderContents('/', '.txt');
moveFile(source, destination)
Moves the file from the source to the destination place. Returns true on success, false otherwise.
Parameters
Returns: Boolean true if the file was moved successfully; false otherwise.
Sample
// Move file based on names.
if (!plugins.file.moveFile('story.txt','story.txt.new'))
application.output('File move failed.');
// Move file based on JSFile instances.
var f = plugins.file.convertToJSFile('story.txt.new');
var fmoved = plugins.file.convertToJSFile('story.txt');
if (!plugins.file.moveFile(f, fmoved))
application.output('File move back failed.');
openFile(file)
Opens the given local file.
The (server local) file will open inside the browser - if supported (sent using "Content-disposition: inline" HTTP header).
Parameters
JSFile file the local file to open. The file should exist and be accessible.
Returns: Boolean success status of the open operation
Sample
var myPDF = plugins.file.createFile('my.pdf');
myPDF.setBytes(data, true)
plugins.file.openFile(myPDF);
openFile(file, webClientTarget, webClientTargetOptions)
Opens the given local file.
The (server local) file will open inside the browser - if supported (sent using "Content-disposition: inline" HTTP header).
Parameters
JSFile file the local file to open. The file should exist and be accessible.
String webClientTarget Target frame or named dialog/window. For example "_self" to open in the same browser window, "_blank" for another browser window. By default "_blank" is used.
String webClientTargetOptions window options used when a new browser window is to be shown; see browser JS 'window.open(...)' documentation.
Returns: Boolean success status of the open operation
Sample
var myPDF = plugins.file.createFile('my.pdf');
myPDF.setBytes(data, true)
plugins.file.openFile(myPDF, "_self", null); // show in the same browser window
openFile(fileName, data, mimeType)
Opens the given data as a file.
The data will open as a file inside the browser - if supported (sent using "Content-disposition: inline" HTTP header).
Parameters
String fileName the name of the file that should open with the given data. Can be null.
Array data the file's binary content.
String mimeType can be left null, and is used for webclient only. Specify one of any valid mime types: https://developer.mozilla.org/en-US/docs/Properly_Configuring_Server_MIME_Types http://www.iana.org/assignments/media-types/media-types.xhtml http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
Returns: Boolean success status of the open operation
Sample
// read or generate pdf file bytes
var bytes = plugins.file.readFile("c:/ExportedPdfs/13542.pdf");
// mimeType variable can be left null
var mimeType = 'application/pdf'
if (!plugins.file.openFile("MonthlyStatistics.pdf", bytes, mimeType))
application.output('Failed to open the file.');
openFile(fileName, data, mimeType, webClientTarget, webClientTargetOptions)
Opens the given data as a file.
The data will open as a file inside the browser - if supported (sent using "Content-disposition: inline" HTTP header).
Parameters
String fileName the name of the file that should open with the given data. Can be null.
Array data the file's binary content.
String mimeType can be left null, and is used for webclient only. Specify one of any valid mime types: https://developer.mozilla.org/en-US/docs/Properly_Configuring_Server_MIME_Types http://www.iana.org/assignments/media-types/media-types.xhtml http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
String webClientTarget Target frame or named dialog/window. For example "_self" to open in the same browser window, "_blank" for another browser window. By default "_blank" is used.
String webClientTargetOptions window options used when a new browser window is to be shown; see browser JS 'window.open(...)' documentation.
Returns: Boolean success status of the open operation
Sample
// read or generate pdf file bytes
var bytes = plugins.file.readFile("c:/ExportedPdfs/13542.pdf");
// mimeType variable can be left null
var mimeType = 'application/pdf'
if (!plugins.file.openFile("MonthlyStatistics.pdf", bytes, mimeType, "_self", null))
application.output('Failed to open the file.');
readFile()
Reads all or part of the content from a binary file. If a file name is not specified, then a file selection dialog pops up for selecting a file. (Web Enabled only for a JSFile argument)
Returns: Array the content of the selected binary file as a byte array, or null if no file is selected or an error occurs.
Sample
// Read all content from the file.
var bytes = plugins.file.readFile('big.jpg');
application.output('file size: ' + bytes.length);
// Read only the first 1KB from the file.
var bytesPartial = plugins.file.readFile('big.jpg', 1024);
application.output('partial file size: ' + bytesPartial.length);
// Read all content from a file selected from the file open dialog.
var bytesUnknownFile = plugins.file.readFile();
application.output('unknown file size: ' + bytesUnknownFile.length);
readFile(file)
Reads all or part of the content from a binary file. If a file name is not specified, then a file selection dialog pops up for selecting a file. (Web Enabled only for a JSFile argument)
Parameters
JSFile file JSFile.
Returns: Array the content of the specified binary file as a byte array, or null if the file cannot be read or an error occurs.
Sample
// Read all content from the file.
var bytes = plugins.file.readFile('big.jpg');
application.output('file size: ' + bytes.length);
// Read only the first 1KB from the file.
var bytesPartial = plugins.file.readFile('big.jpg', 1024);
application.output('partial file size: ' + bytesPartial.length);
// Read all content from a file selected from the file open dialog.
var bytesUnknownFile = plugins.file.readFile();
application.output('unknown file size: ' + bytesUnknownFile.length);
readFile(file, size)
Reads all or part of the content from a binary file. If a file name is not specified, then a file selection dialog pops up for selecting a file. (Web Enabled only for a JSFile argument)
Parameters
Returns: Array a byte array containing up to the specified number of bytes from the given binary file, or null if the file cannot be read or an error occurs.
Sample
// Read all content from the file.
var bytes = plugins.file.readFile('big.jpg');
application.output('file size: ' + bytes.length);
// Read only the first 1KB from the file.
var bytesPartial = plugins.file.readFile('big.jpg', 1024);
application.output('partial file size: ' + bytesPartial.length);
// Read all content from a file selected from the file open dialog.
var bytesUnknownFile = plugins.file.readFile();
application.output('unknown file size: ' + bytesUnknownFile.length);
readFile(file)
Reads all or part of the content from a binary file. If a file name is not specified, then a file selection dialog pops up for selecting a file. (Web Enabled only for a JSFile argument)
Parameters
String file the file path.
Returns: Array the content of the binary file located at the specified file path as a byte array, or null if the file cannot be read or an error occurs.
Sample
// Read all content from the file.
var bytes = plugins.file.readFile('big.jpg');
application.output('file size: ' + bytes.length);
// Read only the first 1KB from the file.
var bytesPartial = plugins.file.readFile('big.jpg', 1024);
application.output('partial file size: ' + bytesPartial.length);
// Read all content from a file selected from the file open dialog.
var bytesUnknownFile = plugins.file.readFile();
application.output('unknown file size: ' + bytesUnknownFile.length);
readFile(file, size)
Reads all or part of the content from a binary file. If a file name is not specified, then a file selection dialog pops up for selecting a file. (Web Enabled only for a JSFile argument)
Parameters
Returns: Array a byte array containing up to the specified number of bytes from the binary file located at the given file path, or null if the file cannot be read or an error occurs.
Sample
// Read all content from the file.
var bytes = plugins.file.readFile('big.jpg');
application.output('file size: ' + bytes.length);
// Read only the first 1KB from the file.
var bytesPartial = plugins.file.readFile('big.jpg', 1024);
application.output('partial file size: ' + bytesPartial.length);
// Read all content from a file selected from the file open dialog.
var bytesUnknownFile = plugins.file.readFile();
application.output('unknown file size: ' + bytesUnknownFile.length);
readTXTFile()
Read all content from a text file. If a file name is not specified, then a file selection dialog pops up for selecting a file. The encoding can be also specified. (Web Enabled only for a JSFile argument)
Returns: String the content of the selected text file as a String, or null if no file was selected.
Sample
// Read content from a known text file.
var txt = plugins.file.readTXTFile('story.txt');
application.output(txt);
// Read content from a text file selected from the file open dialog.
var txtUnknown = plugins.file.readTXTFile();
application.output(txtUnknown);
readTXTFile(file)
Read all content from a text file. If a file name is not specified, then a file selection dialog pops up for selecting a file. The encoding can be also specified. (Web Enabled only for a JSFile argument)
Parameters
JSFile file JSFile.
Returns: String the content of the specified file path as a String, or null if the file is invalid.
Sample
// Read content from a known text file.
var txt = plugins.file.readTXTFile('story.txt');
application.output(txt);
// Read content from a text file selected from the file open dialog.
var txtUnknown = plugins.file.readTXTFile();
application.output(txtUnknown);
readTXTFile(file, charsetname)
Read all content from a text file. If a file name is not specified, then a file selection dialog pops up for selecting a file. The encoding can be also specified. (Web Enabled only for a JSFile argument)
Parameters
Returns: String the content of the specified file as a String, or null if the file is invalid.
Sample
// Read content from a known text file.
var txt = plugins.file.readTXTFile('story.txt');
application.output(txt);
// Read content from a text file selected from the file open dialog.
var txtUnknown = plugins.file.readTXTFile();
application.output(txtUnknown);
readTXTFile(file)
Read all content from a text file. If a file name is not specified, then a file selection dialog pops up for selecting a file. The encoding can be also specified. (Web Enabled only for a JSFile argument)
Parameters
String file the file path.
Returns: String the content of the specified file path as a String, or null if the file is invalid.
Sample
// Read content from a known text file.
var txt = plugins.file.readTXTFile('story.txt');
application.output(txt);
// Read content from a text file selected from the file open dialog.
var txtUnknown = plugins.file.readTXTFile();
application.output(txtUnknown);
readTXTFile(file, charsetname)
Read all content from a text file. If a file name is not specified, then a file selection dialog pops up for selecting a file. The encoding can be also specified. (Web Enabled only for a JSFile argument)
Parameters
Returns: String the content of the specified file path as a String, or null if the file is invalid.
Sample
// Read content from a known text file.
var txt = plugins.file.readTXTFile('story.txt');
application.output(txt);
// Read content from a text file selected from the file open dialog.
var txtUnknown = plugins.file.readTXTFile();
application.output(txtUnknown);
setMaxUploadFileSize(size)
Sets the maximum allowed file size for uploads in KB. Defaults to servoy.webclient.maxuploadsize parameter from Admin page
Parameters
Number size the maximum file size in KB; -1 default - will set value of the'servoy.webclient.maxuploadsize' setting from the Admin page (if any) or zero (no limit); 0 no limit > 0 max file size for upload (kb)
Returns: void
Sample
// set maximum file size to 10 MB
plugins.file.setMaxUploadFileSize(10240);
// remove size limit
plugins.file.setMaxUploadFileSize(0);
showFileOpenDialog(selectionMode, startDirectory, multiselect, filter, callbackfunction)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)
Parameters
Number selectionMode 0=both,1=Files,2=Dirs
JSFile startDirectory JSFile instance of default folder,null=default/previous
Boolean multiselect true/false
Object filter A filter or array of filters on the folder files.
Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument
Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.
Sample
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
/** @type {JSFile} */
var f = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF", "jpg", "gif"));
application.output('File: ' + f.getName());
application.output('is dir: ' + f.isDirectory());
application.output('is file: ' + f.isFile());
application.output('path: ' + f.getAbsolutePath());
// This allows mutliple selection of files, using previous dir and the same filter as above. This also casts the result to the JSFile type using JSDoc.
// if filters are specified, "all file" filter will not show up unless "*" filter is present
/** @type {JSFile[]} */
var files = plugins.file.showFileOpenDialog(1, null, true, new Array("JPG and GIF", "jpg", "gif", "*"));
for (var i = 0; i < files.length; i++)
{
application.output('File: ' + files[i].getName());
application.output('content type: ' + files[i].getContentType());
application.output('last modified: ' + files[i].lastModified());
application.output('size: ' + files[i].size());
}
//for the web and NG you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
plugins.file.showFileOpenDialog(null,null,false,new Array("JPG and GIF", "jpg", "gif"),mycallbackfunction,'Select some nice files')
When handling big files please look at the admin page properties: "servoy.ng_web_client.tempfile.threshold" and "servoy.ng_web_client.temp.uploadir", so that big files are mapped to temp files and saved to a good temp dir
so that in the callback method you can try to rename the temp generated file to something on the filesystem with a specific name. This way there is no need to stream anything again on the server side
(or access the bytes which will load the big file completely in memory)
showFileOpenDialog(selectionMode, startDirectory, multiselect, filter, callbackfunction, title)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)
Parameters
Number selectionMode 0=both,1=Files,2=Dirs
JSFile startDirectory JSFile instance of default folder, null=default/previous
Boolean multiselect true/false
Object filter A filter or array of filters on the folder files.
Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument
String title The tile of the dialog
Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.
Sample
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
/** @type {JSFile} */
var f = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF", "jpg", "gif"));
application.output('File: ' + f.getName());
application.output('is dir: ' + f.isDirectory());
application.output('is file: ' + f.isFile());
application.output('path: ' + f.getAbsolutePath());
// This allows mutliple selection of files, using previous dir and the same filter as above. This also casts the result to the JSFile type using JSDoc.
// if filters are specified, "all file" filter will not show up unless "*" filter is present
/** @type {JSFile[]} */
var files = plugins.file.showFileOpenDialog(1, null, true, new Array("JPG and GIF", "jpg", "gif", "*"));
for (var i = 0; i < files.length; i++)
{
application.output('File: ' + files[i].getName());
application.output('content type: ' + files[i].getContentType());
application.output('last modified: ' + files[i].lastModified());
application.output('size: ' + files[i].size());
}
//for the web and NG you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
plugins.file.showFileOpenDialog(null,null,false,new Array("JPG and GIF", "jpg", "gif"),mycallbackfunction,'Select some nice files')
When handling big files please look at the admin page properties: "servoy.ng_web_client.tempfile.threshold" and "servoy.ng_web_client.temp.uploadir", so that big files are mapped to temp files and saved to a good temp dir
so that in the callback method you can try to rename the temp generated file to something on the filesystem with a specific name. This way there is no need to stream anything again on the server side
(or access the bytes which will load the big file completely in memory)
showFileOpenDialog(selectionMode, startDirectory, multiselect, callbackfunction)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)
Parameters
Number selectionMode 0=both,1=Files,2=Dirs
JSFile startDirectory JSFile instance of default folder,null=default/previous
Boolean multiselect true/false
Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument
Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.
Sample
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
/** @type {JSFile} */
var f = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF", "jpg", "gif"));
application.output('File: ' + f.getName());
application.output('is dir: ' + f.isDirectory());
application.output('is file: ' + f.isFile());
application.output('path: ' + f.getAbsolutePath());
// This allows mutliple selection of files, using previous dir and the same filter as above. This also casts the result to the JSFile type using JSDoc.
// if filters are specified, "all file" filter will not show up unless "*" filter is present
/** @type {JSFile[]} */
var files = plugins.file.showFileOpenDialog(1, null, true, new Array("JPG and GIF", "jpg", "gif", "*"));
for (var i = 0; i < files.length; i++)
{
application.output('File: ' + files[i].getName());
application.output('content type: ' + files[i].getContentType());
application.output('last modified: ' + files[i].lastModified());
application.output('size: ' + files[i].size());
}
//for the web and NG you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
plugins.file.showFileOpenDialog(null,null,false,new Array("JPG and GIF", "jpg", "gif"),mycallbackfunction,'Select some nice files')
When handling big files please look at the admin page properties: "servoy.ng_web_client.tempfile.threshold" and "servoy.ng_web_client.temp.uploadir", so that big files are mapped to temp files and saved to a good temp dir
so that in the callback method you can try to rename the temp generated file to something on the filesystem with a specific name. This way there is no need to stream anything again on the server side
(or access the bytes which will load the big file completely in memory)
showFileOpenDialog(selectionMode, startDirectory, callbackfunction)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)
Parameters
Number selectionMode 0=both,1=Files,2=Dirs
JSFile startDirectory JSFile instance of default folder,null=default/previous
Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument
Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.
Sample
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
/** @type {JSFile} */
var f = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF", "jpg", "gif"));
application.output('File: ' + f.getName());
application.output('is dir: ' + f.isDirectory());
application.output('is file: ' + f.isFile());
application.output('path: ' + f.getAbsolutePath());
// This allows mutliple selection of files, using previous dir and the same filter as above. This also casts the result to the JSFile type using JSDoc.
// if filters are specified, "all file" filter will not show up unless "*" filter is present
/** @type {JSFile[]} */
var files = plugins.file.showFileOpenDialog(1, null, true, new Array("JPG and GIF", "jpg", "gif", "*"));
for (var i = 0; i < files.length; i++)
{
application.output('File: ' + files[i].getName());
application.output('content type: ' + files[i].getContentType());
application.output('last modified: ' + files[i].lastModified());
application.output('size: ' + files[i].size());
}
//for the web and NG you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
plugins.file.showFileOpenDialog(null,null,false,new Array("JPG and GIF", "jpg", "gif"),mycallbackfunction,'Select some nice files')
When handling big files please look at the admin page properties: "servoy.ng_web_client.tempfile.threshold" and "servoy.ng_web_client.temp.uploadir", so that big files are mapped to temp files and saved to a good temp dir
so that in the callback method you can try to rename the temp generated file to something on the filesystem with a specific name. This way there is no need to stream anything again on the server side
(or access the bytes which will load the big file completely in memory)
showFileOpenDialog(selectionMode, startDirectory, multiselect, filter, callbackfunction)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)
Parameters
Number selectionMode 0=both,1=Files,2=Dirs
String startDirectory Path to default folder,null=default/previous
Boolean multiselect true/false
Object filter A filter or array of filters on the folder files.
Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument
Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.
Sample
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
/** @type {JSFile} */
var f = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF", "jpg", "gif"));
application.output('File: ' + f.getName());
application.output('is dir: ' + f.isDirectory());
application.output('is file: ' + f.isFile());
application.output('path: ' + f.getAbsolutePath());
// This allows mutliple selection of files, using previous dir and the same filter as above. This also casts the result to the JSFile type using JSDoc.
// if filters are specified, "all file" filter will not show up unless "*" filter is present
/** @type {JSFile[]} */
var files = plugins.file.showFileOpenDialog(1, null, true, new Array("JPG and GIF", "jpg", "gif", "*"));
for (var i = 0; i < files.length; i++)
{
application.output('File: ' + files[i].getName());
application.output('content type: ' + files[i].getContentType());
application.output('last modified: ' + files[i].lastModified());
application.output('size: ' + files[i].size());
}
//for the web and NG you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
plugins.file.showFileOpenDialog(null,null,false,new Array("JPG and GIF", "jpg", "gif"),mycallbackfunction,'Select some nice files')
When handling big files please look at the admin page properties: "servoy.ng_web_client.tempfile.threshold" and "servoy.ng_web_client.temp.uploadir", so that big files are mapped to temp files and saved to a good temp dir
so that in the callback method you can try to rename the temp generated file to something on the filesystem with a specific name. This way there is no need to stream anything again on the server side
(or access the bytes which will load the big file completely in memory)
showFileOpenDialog(selectionMode, startDirectory, multiselect, filter, callbackfunction, title)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)
Parameters
Number selectionMode 0=both,1=Files,2=Dirs
String startDirectory Path to default folder, null=default/previous
Boolean multiselect true/false
Object filter A filter or array of filters on the folder files.
Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument
String title The tile of the dialog
Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.
Sample
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
/** @type {JSFile} */
var f = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF", "jpg", "gif"));
application.output('File: ' + f.getName());
application.output('is dir: ' + f.isDirectory());
application.output('is file: ' + f.isFile());
application.output('path: ' + f.getAbsolutePath());
// This allows mutliple selection of files, using previous dir and the same filter as above. This also casts the result to the JSFile type using JSDoc.
// if filters are specified, "all file" filter will not show up unless "*" filter is present
/** @type {JSFile[]} */
var files = plugins.file.showFileOpenDialog(1, null, true, new Array("JPG and GIF", "jpg", "gif", "*"));
for (var i = 0; i < files.length; i++)
{
application.output('File: ' + files[i].getName());
application.output('content type: ' + files[i].getContentType());
application.output('last modified: ' + files[i].lastModified());
application.output('size: ' + files[i].size());
}
//for the web and NG you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
plugins.file.showFileOpenDialog(null,null,false,new Array("JPG and GIF", "jpg", "gif"),mycallbackfunction,'Select some nice files')
When handling big files please look at the admin page properties: "servoy.ng_web_client.tempfile.threshold" and "servoy.ng_web_client.temp.uploadir", so that big files are mapped to temp files and saved to a good temp dir
so that in the callback method you can try to rename the temp generated file to something on the filesystem with a specific name. This way there is no need to stream anything again on the server side
(or access the bytes which will load the big file completely in memory)
showFileOpenDialog(selectionMode, startDirectory, multiselect, callbackfunction)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)
Parameters
Number selectionMode 0=both,1=Files,2=Dirs
String startDirectory Path to default folder,null=default/previous
Boolean multiselect true/false
Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument
Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.
Sample
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
/** @type {JSFile} */
var f = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF", "jpg", "gif"));
application.output('File: ' + f.getName());
application.output('is dir: ' + f.isDirectory());
application.output('is file: ' + f.isFile());
application.output('path: ' + f.getAbsolutePath());
// This allows mutliple selection of files, using previous dir and the same filter as above. This also casts the result to the JSFile type using JSDoc.
// if filters are specified, "all file" filter will not show up unless "*" filter is present
/** @type {JSFile[]} */
var files = plugins.file.showFileOpenDialog(1, null, true, new Array("JPG and GIF", "jpg", "gif", "*"));
for (var i = 0; i < files.length; i++)
{
application.output('File: ' + files[i].getName());
application.output('content type: ' + files[i].getContentType());
application.output('last modified: ' + files[i].lastModified());
application.output('size: ' + files[i].size());
}
//for the web and NG you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
plugins.file.showFileOpenDialog(null,null,false,new Array("JPG and GIF", "jpg", "gif"),mycallbackfunction,'Select some nice files')
When handling big files please look at the admin page properties: "servoy.ng_web_client.tempfile.threshold" and "servoy.ng_web_client.temp.uploadir", so that big files are mapped to temp files and saved to a good temp dir
so that in the callback method you can try to rename the temp generated file to something on the filesystem with a specific name. This way there is no need to stream anything again on the server side
(or access the bytes which will load the big file completely in memory)
showFileOpenDialog(selectionMode, startDirectory, callbackfunction)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)
Parameters
Number selectionMode 0=both,1=Files,2=Dirs
String startDirectory Path to default folder,null=default/previous
Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument
Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.
Sample
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
/** @type {JSFile} */
var f = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF", "jpg", "gif"));
application.output('File: ' + f.getName());
application.output('is dir: ' + f.isDirectory());
application.output('is file: ' + f.isFile());
application.output('path: ' + f.getAbsolutePath());
// This allows mutliple selection of files, using previous dir and the same filter as above. This also casts the result to the JSFile type using JSDoc.
// if filters are specified, "all file" filter will not show up unless "*" filter is present
/** @type {JSFile[]} */
var files = plugins.file.showFileOpenDialog(1, null, true, new Array("JPG and GIF", "jpg", "gif", "*"));
for (var i = 0; i < files.length; i++)
{
application.output('File: ' + files[i].getName());
application.output('content type: ' + files[i].getContentType());
application.output('last modified: ' + files[i].lastModified());
application.output('size: ' + files[i].size());
}
//for the web and NG you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
plugins.file.showFileOpenDialog(null,null,false,new Array("JPG and GIF", "jpg", "gif"),mycallbackfunction,'Select some nice files')
When handling big files please look at the admin page properties: "servoy.ng_web_client.tempfile.threshold" and "servoy.ng_web_client.temp.uploadir", so that big files are mapped to temp files and saved to a good temp dir
so that in the callback method you can try to rename the temp generated file to something on the filesystem with a specific name. This way there is no need to stream anything again on the server side
(or access the bytes which will load the big file completely in memory)
showFileOpenDialog(selectionMode, callbackfunction)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)
Parameters
Number selectionMode 0=both,1=Files,2=Dirs
Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument
Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.
Sample
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
/** @type {JSFile} */
var f = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF", "jpg", "gif"));
application.output('File: ' + f.getName());
application.output('is dir: ' + f.isDirectory());
application.output('is file: ' + f.isFile());
application.output('path: ' + f.getAbsolutePath());
// This allows mutliple selection of files, using previous dir and the same filter as above. This also casts the result to the JSFile type using JSDoc.
// if filters are specified, "all file" filter will not show up unless "*" filter is present
/** @type {JSFile[]} */
var files = plugins.file.showFileOpenDialog(1, null, true, new Array("JPG and GIF", "jpg", "gif", "*"));
for (var i = 0; i < files.length; i++)
{
application.output('File: ' + files[i].getName());
application.output('content type: ' + files[i].getContentType());
application.output('last modified: ' + files[i].lastModified());
application.output('size: ' + files[i].size());
}
//for the web and NG you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
plugins.file.showFileOpenDialog(null,null,false,new Array("JPG and GIF", "jpg", "gif"),mycallbackfunction,'Select some nice files')
When handling big files please look at the admin page properties: "servoy.ng_web_client.tempfile.threshold" and "servoy.ng_web_client.temp.uploadir", so that big files are mapped to temp files and saved to a good temp dir
so that in the callback method you can try to rename the temp generated file to something on the filesystem with a specific name. This way there is no need to stream anything again on the server side
(or access the bytes which will load the big file completely in memory)
showFileOpenDialog(callbackfunction)
Shows a file open dialog. Filters can be applied on what type of files can be selected. (Web Enabled, you must set the callback method for this to work)
Parameters
Function callbackfunction A function that takes the (JSFile) array of the selected files as first argument
Returns: Object a JSFile or an array of JSFiles selected by the user, or null if no file was selected.
Sample
// This selects only files ('1'), previous dir must be used ('null'), no multiselect ('false') and
// the filter "JPG and GIF" should be used: ('new Array("JPG and GIF","jpg","gif")').
/** @type {JSFile} */
var f = plugins.file.showFileOpenDialog(1, null, false, new Array("JPG and GIF", "jpg", "gif"));
application.output('File: ' + f.getName());
application.output('is dir: ' + f.isDirectory());
application.output('is file: ' + f.isFile());
application.output('path: ' + f.getAbsolutePath());
// This allows mutliple selection of files, using previous dir and the same filter as above. This also casts the result to the JSFile type using JSDoc.
// if filters are specified, "all file" filter will not show up unless "*" filter is present
/** @type {JSFile[]} */
var files = plugins.file.showFileOpenDialog(1, null, true, new Array("JPG and GIF", "jpg", "gif", "*"));
for (var i = 0; i < files.length; i++)
{
application.output('File: ' + files[i].getName());
application.output('content type: ' + files[i].getContentType());
application.output('last modified: ' + files[i].lastModified());
application.output('size: ' + files[i].size());
}
//for the web and NG you have to give a callback function that has a JSFile array as its first argument (also works in smart), only multi select and the title are used in the webclient, others are ignored
plugins.file.showFileOpenDialog(null,null,false,new Array("JPG and GIF", "jpg", "gif"),mycallbackfunction,'Select some nice files')
When handling big files please look at the admin page properties: "servoy.ng_web_client.tempfile.threshold" and "servoy.ng_web_client.temp.uploadir", so that big files are mapped to temp files and saved to a good temp dir
so that in the callback method you can try to rename the temp generated file to something on the filesystem with a specific name. This way there is no need to stream anything again on the server side
(or access the bytes which will load the big file completely in memory)
streamFile(file)
Stream the given file(path) to the browser with content-disposition:attachment This will not load in the file fully into memory but only stream it right from disk. This can be any filepath on the server, but only the simple file name is exposed as the content disposition header filename. This will throw an exception if anything goes wrong, like the given file is not valid/found.
Parameters
Object file A path string, JSFile or RemoteFile
Returns: void
streamFile(file, contentDisposition)
String the given file(path) to the browser you can provide the content disposition how this should be send (inline or as an attachment) This will not load in the file fully into memory but only stream it right from disk. This can be any filepath on the server, but only the simple file name is exposed. This will throw an exception if anything goes wrong, like the given file is not valid/found.
Parameters
Object file A path string, JSFile or RemoteFile
String contentDisposition can be 'inline' or 'attachment'
Returns: void
streamFile(file, contentDisposition, browserTarget)
String the given file(path) to the browser you can provide the content disposition how this should be send (inline or as an attachment) This will not load in the file fully into memory but only stream it right from disk. This can be any filepath on the server, but only the simple file name is exposed. This will throw an exception if anything goes wrong, like the given file is not valid/found. Give the browser target if you want to open the file inside another tab, most usefull in 'inline' content disposition mode.
Parameters
Object file A path string, JSFile or RemoteFile
String contentDisposition can be 'inline' or 'attachment'
String browserTarget _blank or a specific name to open this in a differnt tab (really only usefull in inline mode)
Returns: void
trackFileForDeletion(file)
If the client's solution is closed, the file given to this method will be deleted. This can be a remote or local file.
This can be used to have temp files within a client that will be cleaned up when the solution is closed. So they live as long as the client has its solution open.
Parameters
JSFile file the file to track
Returns: void
Sample
var file = plugins.file.createFile("newfile.txt");
plugins.file.writeTXTFile(file, "some data");
plugins.file.trackFileForDeletionfile(file);
writeFile(file, data)
Writes the given file to disk.
If "file" is a String (like 'mypdffile.pdf' to hint the browser what it is) the user will get prompted by the browser to save the file (sent using "Content-disposition: attachment" HTTP header). If it is a JSFile instance in this case it will be saved as a file on the server.
Parameters
Returns: Boolean true if the binary data was successfully written to the file; false otherwise
Sample
/**@type {Array<byte>}*/
var bytes = new Array();
for (var i=0; i<1024; i++)
bytes[i] = i % 100;
var f = plugins.file.convertToJSFile('bin.dat');
if (!plugins.file.writeFile(f, bytes))
application.output('Failed to write the file.');
// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: https://developer.mozilla.org/en-US/docs/Properly_Configuring_Server_MIME_Types
var mimeType = 'application/vnd.ms-excel'
if (!plugins.file.writeFile(f, bytes, mimeType))
application.output('Failed to write the file.');
writeFile(file, data, mimeType)
Writes the given file to disk.
If "file" is a String (like 'mypdffile.pdf' to hint the browser what it is) the user will get prompted by the browser to save the file (sent using "Content-disposition: attachment" HTTP header). If it is a JSFile instance in this case it will be saved as a file on the server.
Parameters
JSFile file a local JSFile
Array data the data to be written
String mimeType the mime type (used in Web-Client)
Returns: Boolean true if the binary data was successfully written to the file; false otherwise.
Sample
/**@type {Array<byte>}*/
var bytes = new Array();
for (var i=0; i<1024; i++)
bytes[i] = i % 100;
var f = plugins.file.convertToJSFile('bin.dat');
if (!plugins.file.writeFile(f, bytes))
application.output('Failed to write the file.');
// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: https://developer.mozilla.org/en-US/docs/Properly_Configuring_Server_MIME_Types
var mimeType = 'application/vnd.ms-excel'
if (!plugins.file.writeFile(f, bytes, mimeType))
application.output('Failed to write the file.');
writeFile(file, data)
Writes the given file to disk.
If "file" is a String (like 'mypdffile.pdf' to hint the browser what it is) the user will get prompted by the browser to save the file (sent using "Content-disposition: attachment" HTTP header). If it is a JSFile instance in this case it will be saved as a file on the server.
Parameters
Returns: Boolean true if the binary data was successfully written to the file path; false otherwise.
Sample
/**@type {Array<byte>}*/
var bytes = new Array();
for (var i=0; i<1024; i++)
bytes[i] = i % 100;
var f = plugins.file.convertToJSFile('bin.dat');
if (!plugins.file.writeFile(f, bytes))
application.output('Failed to write the file.');
// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: https://developer.mozilla.org/en-US/docs/Properly_Configuring_Server_MIME_Types
var mimeType = 'application/vnd.ms-excel'
if (!plugins.file.writeFile(f, bytes, mimeType))
application.output('Failed to write the file.');
writeFile(file, data, mimeType)
Writes the given file to disk.
If "file" is a String (like 'mypdffile.pdf' to hint the browser what it is) the user will get prompted by the browser to save the file (sent using "Content-disposition: attachment" HTTP header). If it is a JSFile instance in this case it will be saved as a file on the server.
Parameters
String file the file path as a String
Array data the data to be written
String mimeType the mime type (used in Web-Client)
Returns: Boolean true if the binary data was successfully written to the file path; false otherwise.
Sample
/**@type {Array<byte>}*/
var bytes = new Array();
for (var i=0; i<1024; i++)
bytes[i] = i % 100;
var f = plugins.file.convertToJSFile('bin.dat');
if (!plugins.file.writeFile(f, bytes))
application.output('Failed to write the file.');
// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: https://developer.mozilla.org/en-US/docs/Properly_Configuring_Server_MIME_Types
var mimeType = 'application/vnd.ms-excel'
if (!plugins.file.writeFile(f, bytes, mimeType))
application.output('Failed to write the file.');
writeTXTFile(file, text_data)
Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)
Parameters
Returns: Boolean true if the text data was successfully written to the file; false otherwise.
Sample
var fileNameSuggestion = 'myspecialexport.tab'
var textData = 'load of data...'
var success = plugins.file.writeTXTFile(fileNameSuggestion, textData);
if (!success) application.output('Could not write file.');
// For file-encoding parameter options (default OS encoding is used), http://download.oracle.com/javase/1.4.2/docs/guide/intl/encoding.doc.html
// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: http://www.w3schools.com/media/media_mimeref.asp'
writeTXTFile(file, text_data, charsetname)
Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)
Parameters
Returns: Boolean true if the text data was successfully written to the specified file; false otherwise.
Sample
var fileNameSuggestion = 'myspecialexport.tab'
var textData = 'load of data...'
var success = plugins.file.writeTXTFile(fileNameSuggestion, textData);
if (!success) application.output('Could not write file.');
// For file-encoding parameter options (default OS encoding is used), http://download.oracle.com/javase/1.4.2/docs/guide/intl/encoding.doc.html
// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: http://www.w3schools.com/media/media_mimeref.asp'
writeTXTFile(file, text_data, charsetname, mimeType)
Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)
Parameters
JSFile file JSFile
String text_data Text to be written.
String charsetname Charset name.
String mimeType Content type (used only on web).
Returns: Boolean true if the text data was successfully written to the specified file; false otherwise.
Sample
var fileNameSuggestion = 'myspecialexport.tab'
var textData = 'load of data...'
var success = plugins.file.writeTXTFile(fileNameSuggestion, textData);
if (!success) application.output('Could not write file.');
// For file-encoding parameter options (default OS encoding is used), http://download.oracle.com/javase/1.4.2/docs/guide/intl/encoding.doc.html
// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: http://www.w3schools.com/media/media_mimeref.asp'
writeTXTFile(file, text_data)
Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)
Parameters
Returns: Boolean true if the text data was successfully written to the specified file path; false otherwise.
Sample
var fileNameSuggestion = 'myspecialexport.tab'
var textData = 'load of data...'
var success = plugins.file.writeTXTFile(fileNameSuggestion, textData);
if (!success) application.output('Could not write file.');
// For file-encoding parameter options (default OS encoding is used), http://download.oracle.com/javase/1.4.2/docs/guide/intl/encoding.doc.html
// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: http://www.w3schools.com/media/media_mimeref.asp'
writeTXTFile(file, text_data, charsetname)
Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)
Parameters
Returns: Boolean true if the text data was successfully written to the specified file path; false otherwise.
Sample
var fileNameSuggestion = 'myspecialexport.tab'
var textData = 'load of data...'
var success = plugins.file.writeTXTFile(fileNameSuggestion, textData);
if (!success) application.output('Could not write file.');
// For file-encoding parameter options (default OS encoding is used), http://download.oracle.com/javase/1.4.2/docs/guide/intl/encoding.doc.html
// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: http://www.w3schools.com/media/media_mimeref.asp'
writeTXTFile(file, text_data, charsetname, mimeType)
Writes data into a text file. (Web Enabled: file parameter can be a string 'mytextfile.txt' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)
Parameters
String file The file path.
String text_data Text to be written.
String charsetname Charset name.
String mimeType Content type (used only on web).
Returns: Boolean true if the text data was successfully written to the specified file path; false otherwise.
Sample
var fileNameSuggestion = 'myspecialexport.tab'
var textData = 'load of data...'
var success = plugins.file.writeTXTFile(fileNameSuggestion, textData);
if (!success) application.output('Could not write file.');
// For file-encoding parameter options (default OS encoding is used), http://download.oracle.com/javase/1.4.2/docs/guide/intl/encoding.doc.html
// mimeType variable can be left null, and is used for webclient only. Specify one of any valid mime types as referenced here: http://www.w3schools.com/media/media_mimeref.asp'
writeXMLFile(file, xml_data)
Writes data into an XML file. The file is saved with the encoding specified by the XML itself. (Web Enabled: file parameter can be a string 'myxmlfile.xml' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)
Parameters
Returns: Boolean true if the XML data was successfully written to the specified file; false otherwise.
Sample
var fileName = 'form.xml'
var xml = controller.printXML()
var success = plugins.file.writeXMLFile(fileName, xml);
if (!success) application.output('Could not write file.');
writeXMLFile(file, xml_data, encoding)
Writes data into an XML file. The file is saved with the encoding specified by the XML itself. (Web Enabled: file parameter can be a string 'myxmlfile.xml' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)
Parameters
JSFile file a local JSFile
String xml_data the xml data to write
String encoding the specified encoding
Returns: Boolean true if the XML data was successfully written to the file; false otherwise.
Sample
var fileName = 'form.xml'
var xml = controller.printXML()
var success = plugins.file.writeXMLFile(fileName, xml);
if (!success) application.output('Could not write file.');
writeXMLFile(file, xml_data)
Writes data into an XML file. The file is saved with the encoding specified by the XML itself. (Web Enabled: file parameter can be a string 'myxmlfile.xml' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)
Parameters
Returns: Boolean true if the XML data was successfully written to the specified file path; false otherwise.
Sample
var fileName = 'form.xml'
var xml = controller.printXML()
var success = plugins.file.writeXMLFile(fileName, xml);
if (!success) application.output('Could not write file.');
writeXMLFile(file, xml_data, encoding)
Writes data into an XML file. The file is saved with the encoding specified by the XML itself. (Web Enabled: file parameter can be a string 'myxmlfile.xml' to hint the browser what it is, if it is a JSFile instance it will be saved on the server)
Parameters
String file the file path as a String
String xml_data the xml data to write
String encoding the specified encoding
Returns: Boolean true if the XML data was successfully written to the specified file path; false otherwise.
Sample
var fileName = 'form.xml'
var xml = controller.printXML()
var success = plugins.file.writeXMLFile(fileName, xml);
if (!success) application.output('Could not write file.');
Last updated
Was this helpful?