Note:

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

Web services files handling: Difference between revisions

From MoodleDocs
m (Protected "Web services files handling": Developer Docs Migration ([Edit=Allow only administrators] (indefinite)))
 
(16 intermediate revisions by 7 users not shown)
Line 1: Line 1:
== Summary ==
{{Template:Migrated|newDocId=/docs/apis/subsystems/external/files}}
 
Since Moodle 2.0, we provide web service functions to upload and download files, they are:
 
# moodle_file_get_files (Deprecated, use core_files_get_files since moodle 2.2 onward)
# moodle_file_upload (Deprecated, use core_files_upload since moodle 2.2 onward)
 
File contents are encoded in base64 for web service transmission, it's not efficient, for mobile devices, there isn't enough memory to decode/encode web service request/response contains large files.
 
So we developed alternative way to upload/download files for web service clients.
 
 
== File upload ==
 
The entry point is /webservice/upload.php, simply use HTTP POST method to upload files, it requires a web service token for authentication. If the upload is successfully, the files will be saved in the user private file area. The files information will be returned in JSON format. If an error occurs, an error message will be sent back in JSON format too.
 
Look at the [https://github.com/moodlehq/sample-ws-clients/tree/master/PHP-HTTP-filehandling code example on Github].
 
== File download ==
We don't serve the files through /pluginfile.php for web service client, because this script require user's login session to work, it might not an option for web service client, so we created /webservice/pluginfile.php to serve files like /pluginfile.php do but requires web service token for authentication, to use this script, please note:
 
# The service associated with this token must enable allow download flag in advanced service settings
# Web service must be valid
 
 
 
 
 
 
 
== See also ==
* [[Web_services|Web services developer documentation]]
* [[:en:Web_services|Web services user documentation]]
 
[[Category:Web_Services]]

Latest revision as of 06:13, 22 December 2022

Important:

This content of this page has been updated and migrated to the new Moodle Developer Resources. The information contained on the page should no longer be seen up-to-date.

Why not view this page on the new site and help us to migrate more content to the new site!