FileSystemPlugIn Developer Guide

Introducing the FileSystem plug-in

The FileSystem plug-in(FSP for now) is an extension for the jWebSocket framework to provide support for the basics “file uploads management” operations in WebSocket applications.

Using the FSP you can easily save files from the client to the server, load in the client previously saved files, remove or list previously stored files and also send files directly to other connected clients.
 

// loading a ZIP file from the private alias
client.fileLoad('file.zip', jws.FileSystemPlugIn.ALIAS_PRIVATE, {
  OnResponse: function( aToken ) {
    console.log(aToken);
  }
});
// listing recursive files on the public alias
client.fileGetFilelist(
  jws.FileSystemPlugIn.ALIAS_PUBLIC, 
  ['*.*'], {
    recursive: true,
    OnResponse: function(aToken){
      console.log(aToken)
    }
  }
);



 

WebSocket applications and file uploading

The WebSocket technology changed the traditional way to create web applications. File uploads in one of the operations that has been “updated” to re-use the benefits of a permanent and bidirectional socket connection between the client and the server. The web browsers also started supporting a new File API that allows the web applications to read and write files in the client-side.

A WebSocket file upload algorithm using the FSP can be summarized as following:

  • Select a file (or many)
  • Read the file content (Base64 encoding)
  • Save the file(s) in the server

FSP is very easy to use

Saving a file in the server:

//The file
var FILENAME = “test.txt”;
var FILECONTENT = “This is the test.txt content.”;
//Calling the “fileSave” method in the jWebSocket client instance 
client.fileSave( FILENAME, FILECONTENT, {
  encode: true,  
  scope: jws.SCOPE_PRIVATE, 
  OnResponse: function( aResponse ) {
    alert(“File saved successfully”);
  }
}); 

Loading a file from the server:

//The file
var FILENAME = “test.txt”;
//Calling the “fileLoad” method in the jWebSocket client instance 
client.fileLoad( FILENAME, jws.FileSystemPlugIn.ALIAS_PRIVATE, {
  OnResponse: function( aResponse ) {
    alert(“The file content is: ” + aResponse.data)
  }
});

The “scope” argument

Some operations with the FSP requires an argument called “scope”. The scope argument indicates if the file will be private to the owner user or will be public for reading or modification purposes to others. The users can only store files in their private file-system directory (private alias targeted) or in a user's common public directory (public alias targeted).

The supported scope argument values are:

  • jws.SCOPE_PRIVATE: The file will be stored in the private alias.
  • jws.SCOPE_PUBLIC: The file will be stored in the public alias.

The “alias” argument

The term “alias” in the FSP represents a unique short name associated to a directory path. Example: “privateDir” => “${JWEBSOCKET_HOME}filesystem/ private/{username}/”.

There are three core aliases in the FSP, these are:

  • privateDir (jws.FileSystemPlugIn.ALIAS_PRIVATE): Targets the user's private directory. Default value is ${JWEBSOCKET_HOME}/filesystem/private/{username}/
  • publicDir (jws.FileSystemPlugIn.ALIAS_PUBLIC): Targets the user's common public directory. Default value is ${JWEBSOCKET_HOME}/filesystem/public/
  • webRoot: Targets the HTTP web folder of the “publicDir” alias directory. Default value is http://localhost/public/

The FSP supports however infinite aliases, but the users can only execute the following operations on them:

  • fileLoad: Load a file from the alias.
  • fileExists: Check if a file exists on the alias.
  • fileGetFilelist: Retrieve the alias file list.

The aliases allows the applications to share with the clients read-only directories. Usage example: The server-side application PDF report's directory.

Publications

Learn more about WebSockets in general, get background information and gain deeper insight!

Join jWebSocket

Wether developer, designer or translator – join the jWebSocket team and grow together with our success!

Copyright © 2013 Innotrade GmbH. All rights reserved.