This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Working with Files in Drupal


Overview

The following operations allow you to work with files. Click an operation name to see details on how to use it.

For a sample proxy service that illustrates how to work with files, see Sample configuration

OperationDescription

createFile

Creates a file.

getFile

Retrieves a file.

listFilesRetrieves all files.

Operation details

This section provides further details on the operations related to files.

Creating a file

The createFile operation creates a file with base64 encoded data.

createFile
<drupal.createFile>
    <status>{$ctx:status}</status>
    <file>{$ctx:file}</file>
	<fileName>{$ctx:fileName}</fileName>
</drupal.createFile>
Properties
  • status: Represents the bitmapped field indicating the status of the file. Temporary (0) or permanent (1).
  • file: The base 64 encoded string of the image.
  • fileName: Name of the file with no path components. E.g. image.png
   Sample request

Following is a sample REST/JSON request that can be handled by the createFile operation.

Sample Request for createFile
{
    "responseType": "xml",
    "apiUrl": "http://172.22.217.40/restapi",
    "userName": "samliyanage",
    "password": "1qaz2wsx@",
    "status":"0",
    "file":"aHR0cHM6Ly9lbmNyeXB0ZWQtdGJuMi5nc3RhdGljLmNvbS9pbWFnZXM/cT10Ym46QU5kOUdjVEptTlc0dXd0eWRTdzdwYTdRVE9KVnhBRE1PWTAwMzRfY3JDaFNKWTkzb19LNGNsN08=",
    "fileName":"image.jpg"
}
Related Drupal documentation

https://www.drupal.org/project/rest_server

Retrieving a file

The getFile operation retrieves a file.

getFile
<drupal.getFile>
	<fileId>{$ctx:fileId}</fileId>
</drupal.getFile>
Properties
  • fileId: The unique identifier of the file.
   Sample request

Following is a sample REST/JSON request that can be handled by the getFile operation.

Sample Request for getFile
{
    "responseType":"json",
    "apiUrl":"https://172.22.217.40/restapi",
    "userName":"samliyanage",
    "password":"1qaz2wsx@",
    "fileId":"46"
}
Related Drupal documentation

https://www.drupal.org/project/rest_server

Retrieving all files 

The listFiles operation retrieves all files.

listFiles
<drupal.listFiles>
    <page>{$ctx:page}</page>
    <pageSize>{$ctx:pageSize}</pageSize>
    <parameters>{$ctx:parameters}</parameters>
	<fields>{$ctx:fields}</fields>
</drupal.listFiles>
Properties
  • page: The page number of results to return.
  • pageSize: Number of items to be returned.
  • parameters: An Array of JSON objects containing fields and values. Used to filter out the items to be returned.
  • fields: The fields to be returned.
   Sample request

Following is a sample REST/JSON request that can be handled by the listFiles operation.

Sample Request for listFiles
{
    "responseType": "xml",
    "apiUrl": "http://172.22.217.40/restapi",
    "userName": "samliyanage",
    "password": "1qaz2wsx@",
    "page": "1",
    "pageSize": "2",
    "parameters": {"filename":"image2.png"},
    "fields": "filename"
}
Related Drupal documentation

 https://www.drupal.org/project/rest_server

Sample configuration

Following is a sample proxy service that illustrates how to connect to Drupal with the init operation and use the createFile operation. The sample request for this proxy can be found in the createFile sample request.

Sample Proxy
<?xml version="1.0" encoding="UTF-8"?>
	<proxy xmlns="http://ws.apache.org/ns/synapse" name="drupal_createFile" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
	 <target>
	 <inSequence onError="faultHandlerSeq">
      <property name="responseType" expression="json-eval($.responseType)"/>
      <property name="apiUrl" expression="json-eval($.apiUrl)"/>
      <property name="userName" expression="json-eval($.userName)"/>
      <property name="password" expression="json-eval($.password)"/>
      <property name="status" expression="json-eval($.status)"/>
      <property name="file" expression="json-eval($.file)"/>
      <property name="fileName" expression="json-eval($.fileName)"/>
      <drupal.init>
         <responseType>{$ctx:responseType}</responseType>
         <apiUrl>{$ctx:apiUrl}</apiUrl>
         <userName>{$ctx:userName}</userName>
         <password>{$ctx:password}</password>
      </drupal.init>
      <drupal.createFile>
         <status>{$ctx:status}</status>
         <file>{$ctx:file}</file>
         <fileName>{$ctx:fileName}</fileName>
      </drupal.createFile>
	   <respond/>
	 </inSequence>
	  <outSequence>
	   <send/>
	  </outSequence>
	 </target>
   <description/>
  </proxy>