[Download] | [Documentation Home] | [Release Note]

File App Service Sample

Introduction

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

  • Streaming Support :- With data streaming functionality, when a service client make 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 by using Base64 encoding to store and retrive non-textual data, such as data files and BLOB fields in databases.

Prerequisites

The sample data service "FileService" should be deployed as per the instructions mentioned in Deploying Samples section.

Running the Sample

A GUI based application is used here in showing the above mentioned features. As shown in Data Services Clients Sample, run the command "ant file_service_app", to execute the application.

Service Definition

The data service is based around the functionality of transferring and retrieval of file data between the client and a database. Below contains the list of queries that is being used in the data service in carrying out the aforementioned actions.

  • createNewFileQuery: Creates a new file given the file name and the type.
  • appendDataToFileQuery: This query appends new data to the given the file to be appended to. By sending in file chunks, data streaming can also be done when sending the data as well.
  • deleteFileQuery: Deleted a file given the file name.
  • checkFileExistsQuery: Checks if a file with the given file name exists.
  • getFileRecordsQuery: Returns all data records associated with a specific file.
  • getFileNamesQuery: Returns all the name of the files in the database.
  • getFileTypeQuery: Returns the file type given the file name.
  • getFileSizeQuery: Returns the size of a file given the file name.

By using the combined functionality of the above queries, we can create a sample file management system with the use of data services.

Sample Run

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 1 shows a file upload in progress.

Figure 1: Uploading a file.

Downloading Files

Select a file you want to download from the file list and pressing download. Then after selecting the path to be saved, the file data will be retrived from the server and will be saved on local disk. You will notice that, when you click download, the data starts receiving immediately, as indicated by the progress bar. This is possible because of the data streaming capability of WSO2 Data Services Server.

Figure 2: Downloading a file.

Previewing Files

Images can be previewed using this app. Select an image file and when you click preview, it will download the image to memory, and will be showed in the preview panel.

Figure 3: Previewing a file.

Deleting Files

To delete a file from the server, select the file name from the list and press the delete button. This will invoke a data service operation, and will remove the file data from the database.