Currently the Lightwork team is adding addition web service functions to Moodle (see MDL-31409 and http://docs.moodle.org/dev/Lightwork).
One web service function that we are adding is called mod_assign_export_submissions and will download one or all student submission files for an assignment package as a zip file (this is similar to selecting the "Download all assignments as a zip" on the Moodle assignment submissions page).
Other web services that we are building will also download multiple files packaged in zip format.
Unfortunately, the existing web services do not support efficient file downloads and the current file download functionality is by using an independent script such as pluginfile.php.
We have identified 3 options for solving this problem:
1) Create another independent script like pluginfile.php that downloads a zip file containing submission files for an assignment
Advantage: Simplest and easiest solution
Disadvantage: An independent script is not a web services function and is not part of services.php and the externallib.php structure. The script needs to be called directly - e.g http://<moodle>/mod/assign/export_submissions.php and not through the standard mechanism
2) Add special handling into webservices/<protocol>/server.php so that web service functions that download files are recognised as a special case and registered handlers are used to call the file download process. E.g, when http://<moodle>/webservices/rest/server.php?WSFUNCTION=mod_assign_export_submissions is called, it is recognised to be a file download and is processed through a handler
Advantage: Allows the standard web service framework to be used
Disadvantage: The required changes to the web service will be awkward to implement and do not fit in well with the current framework
3) Add a new structure "external_file" to the web services. Currently the web services framework support 3 data type, external_multiple_structure, external_single_structure, and external_value. The new "external_file" will contain the filename and file itself for webservice's return().
We then change the webservices handling logic to check when the return type is of external_file and generate a binary file streaming HTTP Response as opposed to generating the regular Response data structure.
This requires 2 implementations, 1 for REST and 1 for the other protocols (as all AMF/XmlRPc/SOAP used 1 implementation based on Zend).
Advantage: This technique fits well with the current web services structure and integrates file download into the existing framework
Disadvantage: It is the most complex implementation
We propose option 3 and are currently prototyping this method with the new web service function mod_assign_export_submissions
Please let us know what you think and whether there is anything we have overlooked.