FileService Class

Provides a set of web methods used to manage and view files on the server

Constructors

FileService( )
FileService( javaxt.io.Directory baseDir )

Public Methods

getList( ServiceRequest request ) returns ServiceResponse
Returns a ServiceResponse with JSON object representing files and folders in a given path. Optional parameters include filter, sort, hidden, offset, and limit.
getFile( ServiceRequest request ) returns ServiceResponse
Returns a ServiceResponse with an InputStream associated with a file. Headers for the ServiceResponse are set with file metadata (e.g. content type, file size, and date). Caller can add additional response headers such as the content disposition to make the file "downloadable". See ServiceResponse.setContentDisposition() for more information.
getPhysicalFile( ServiceRequest request ) returns File
Returns a File associated with a given ServiceRequest
upload( ServiceRequest request ) returns ServiceResponse
Used to upload files to the server
requestServiceRequest with "multipart/form-data" encoded data
upload( ServiceRequest request, Callback callback ) returns ServiceResponse
Used to upload files to the server. The ServiceRequest must contain "multipart/form-data" encoded data. The form data must includes a "path" variable and at least one file.
requestServiceRequest with "multipart/form-data" encoded data
callbackOptional callback. Called after a file has been uploaded. If the request payload contains multiple files, the callback will be called multiple times - once for each file after it had been uploaded. The callback record will contain the following fields:
  • file: A javaxt.io.File representing uploaded file on the server
  • path: String representing the relative or absolute path to the upload directory
  • op: String representing the operation that was performed (e.g. "create" or "update")
Example:
    fileService.upload(request, (Record record)->{

        String path = record.get("path").toString();
        javaxt.io.File file = (javaxt.io.File) record.get("file").toObject();
        path += file.getName();

        NotificationService.notify(record.get("op").toString(), "File", new javaxt.utils.Value(path));
    });    

Public Classes