This documentation is for WSO2 Data Services Server 3.2.2. View documentation for the latest release.
File App Service Sample - Data Services Server 3.2.2 - WSO2 Documentation
Skip to end of metadata
Go to start of metadata

About the sample

This sample demonstrates a file upload/download/preview application with the use of several features available in the WSO2 Data Services Server. Some notable functions are listed below.

  • Streaming Support : With the data streaming functionality, when a service client makes a request, the result is streamed to the service client rather than building the full result in the server and returning it. This allows virtually unlimited payload sizes in the result, and the response is instantaneous to the client.
  • Binary Data : Binary data is handled using Base64 encoding to store and retrive non-textual data, such as data files and BLOB fields in databases.
Service description

The sample data service used here (FileService) transfers and retrieves file data between the client and a database. The list of queries used by the data service to carry out the actions are as follows.

  • createNewFileQuery: Creates a new file when the file name and type is given.
  • appendDataToFileQuery: Appends new data to a given file. By sending in file chunks, data streaming can also be done while sending the data.
  • deleteFileQuery: Deletes a file when the file name is given.
  • checkFileExistsQuery: Checks if a file with a given file name exists.
  • getFileRecordsQuery: Returns all data records associated with a specific file.
  • getFileNamesQuery: Returns the names of the files in the database.
  • getFileTypeQuery: Returns the file type of a given file name.
  • getFileSizeQuery: Returns the size of a given file name.

By combining functionality of the above queries, we can create a sample file management system with the use of data services. See Data Services and Resources for a definition of data services, queries and operations.

Building the sample

The sample data service, FileService should be deployed using the instructions in Samples Setup.

Running the sample

To execute the application, you have to run the ant file_service_app command as described in the Data Services Clients section. 

  • Uploading files
    When uploading files, after a file is selected to be sent, the file is read and the data is transferred in chunks to the server. Figure below shows a file upload in progress.
  • Downloading files
    Select a file you want to download from the file list and press download. After selecting the path to be saved, the file data is retrieved from the server and saved on the local disk. When the user clicks download, the data download starts immediately as indicated by the progress bar. This is possible because of the data streaming capability of the WSO2 Data Services Server.
  • Previewing files
    Images can be previewed using this application. Select an image file and click Preview. The image is downloaded to memory and shown in the preview panel:
  • Deleting files
    To delete a file from the server, select the file name from the list and press Delete. This invokes a data service operation and removes the file from the database. 
  • No labels