Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Rev: 1384958006482
Div
styledisplay:none

DO NOT EDIT THE CONTENT OF THIS PAGE DIRECTLY (EXCEPT INSIDE THE DIV BELOW WITH ID=DESCRIPTION), UNLESS YOU KNOW WHAT YOU'RE DOING.
THE STRUCTURE OF THE CONTENT IS VITAL IN BEING ABLE TO AUTO UPDATE THE CONTENT THROUGH THE DOC GENERATOR. Enter additional information related to this 'class' inside the {div} macro with 'id=description'

Div
iddescription

The File plugin provides functionality to work with files.

Main features are:

  • Creating temporary files
  • Reading from and writing to the filesystem
  • Retrieving information on files and directories on the file system
  • Streaming files between the Smart Client and the Server (and vise versa)
    The stream methods are not directly useful for the WebClient, because this is really streaming of files between a client and a server, and the client code of the WebClient is already running on the server, so you are the streaming data withing the same process. The streaming for the webclientis handled by the browser code.

When using the File plugin, it's important to take into account the differences and compatibility between different clients:

  • Interacting with the file system through the plugin in a Smart Client happens client-side, so on the machine where the Smart Client is launched. On all other clients (Web, Headless & Batchprocessor), the operations are performed on the Server.
  • All showXxxxDialog(...) functions interact with the user through a UI. These function can only be used in Clients that provide a UI, like the Smart and Web Client.
  • The showXxxxDialog(...) functions, when used in the Web Client, have certain limitations due to being operated in a browser. Browser security (currently) limits interaction with the local file system, except for single file select operations initiated by the user clicking a button.

Many functions work only in the smart client or only on the server in the Headless or WebClient, some work in the WebClient's browser and that is mentioned in the doc (WebClient enabled) most of the time an extra parameter or some certain state must be set like a callback function, because in the WebClient the function will not wait for a result and then return the result, but will go on, and then the callback is called when it is done. (like showFileOpenDialog)
You have no control directly of the real files in a a WebClient, so the files on the pc of the browser. You can't directly target them to load into the client, or with saving you can't specify the target directory where it is getting saved. This is all fully controlled by the browser.
When using the streaming features of the File plugin, make sure that you set the directory "servoy.FileServerService.defaultFolder" of the File server plugin settings in the admin page. Don't reply on the default behavior, specify your own writable directory.

Because the File plugin works with 3 different kind of files (LocalFiles on disk, RemoteFiles on the server when streaming is used and Uploaded files from the webclient when the browser uploads a file), not all things that you call on a JSFile object will give you data that you expect, for example a Uploaded file that you get back in the callback method of a showFileOpenDialog in the webclient does not represent an actual File object on the server. It is a binary data object (blob) that is only in memory, so getParentFile() or getPath() will return null in these cases, you don't get access or a reference to the file path or directory of the browsers pc. Also setBytes() will result in an exception. Best things to use is the getBytes() method if you want to get the bytes and store that, that will work for all 3 types. If you want to store the bytes that a webclient uploaded in another file the quickest way to do that is to use:

var fileOnServer = plugins.file.convertToJSFile('/path/to/file/on/server');

plugins.file.writeFile(fileOnServer,uploadedFile.getBytes());

...