Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Web services:Files: Difference between revisions

From MoodleDocs
mNo edit summary
Line 12: Line 12:
This function is used to browse files.
This function is used to browse files.


It takes 5 parameters:
It takes 5 parameters, all of them are optional, if you provide no parameters, it will return the top level content of moodle repository.
 
* contextid
* contextid
* itemid
* itemid
Line 35: Line 36:
This function is used to get the download url of a sepcific file.
This function is used to get the download url of a sepcific file.


It takes 5 parameters:
It takes 5 parameters, all of them are mandatory, invaild parameter will raise an exception
 
* contextid
* contextid
* itemid
* itemid
Line 49: Line 51:
This function is used to upload a file.
This function is used to upload a file.


It takes 5 parameters:
We have two choice to upload a file to moodle (need a decision)
 
# Encoding the file in a base64 string, and encapsulate it in xmlrpc/soap/rest request body, it is not quite reliable to deal with large files
# Uploading a file to moodle draft area first, got the file information, and pass the file information by web service
 
It takes 5 parameters, all of them are mandatory:
 
* contextid
* contextid
* filename
* filename
* filepath
* filepath
* filearea
* filearea
* file (a pointer of file)


It will return a boolean value, true/false.
It will return a boolean value, true/false.


The service name is "moodle_file_put_file", defined in lib/db/services.php
The service name is "moodle_file_put_file", defined in lib/db/services.php

Revision as of 07:39, 20 November 2009

These APIs will be used to browse Moodle files by Moodle Web Services.

class moodle_file_external()

This class implements the interface to moodle files, for browsing, downloading and uploading files. It is defined in files/externals.php.

We cannot return the whole files tree by web service API, because to make sure the web services working in every language and platform, we need to define a fixed data structure of return value, but the files tree can change all the time. See more information about web services at: External_services_description.

The class contains following methods:

get_files

This function is used to browse files.

It takes 5 parameters, all of them are optional, if you provide no parameters, it will return the top level content of moodle repository.

  • contextid
  • itemid
  • filename
  • filepath
  • filearea

It will return an array, can be described as PHP array:

$files = array(
  'path' => array(array('name'=>'root', 'path=>'/'), array('name'=>'subdir', 'path=>'/sub/')),
  'files' => array(
       array('filename'=>'readme', 'filepath'=>'/', 'filearea'=>'forum', 'itemid'=>110, 'contextid'=>1, 'isdir'=>true),
       array('filename'=>'changes', 'filepath'=>'/', 'filearea'=>'forum', 'itemid'=>112, 'contextid'=>1, 'isdir'=>false),
     )
);

The service name is "moodle_file_get_files", defined in lib/db/services.php.

get_url

This function is used to get the download url of a sepcific file.

It takes 5 parameters, all of them are mandatory, invaild parameter will raise an exception

  • contextid
  • itemid
  • filename
  • filepath
  • filearea

It will return the URL of the file.

The service name is "moodle_file_get_url", defined in lib/db/services.php

put_file

This function is used to upload a file.

We have two choice to upload a file to moodle (need a decision)

  1. Encoding the file in a base64 string, and encapsulate it in xmlrpc/soap/rest request body, it is not quite reliable to deal with large files
  2. Uploading a file to moodle draft area first, got the file information, and pass the file information by web service

It takes 5 parameters, all of them are mandatory:

  • contextid
  • filename
  • filepath
  • filearea

It will return a boolean value, true/false.

The service name is "moodle_file_put_file", defined in lib/db/services.php