I am developing an Android app, which will upload content to a user's private files in my Moodle installation using the REST webservice core_files_upload provided by Moodle. core_files_upload takes the following parameters:
contextid
component
filearea
itemid
filepath
filename
filecontent
The documentation for the Moodle Web Services isn't very detailed so I have pieced together what I can from the Moodle forums and Google searches, but I feel I have come to a dead end. From examples I have seen that the parameters take the following values:
contextid: int - not sure whether this is the userid
component: "user"
filearea: "private"
itemid: 0
filepath: "/"
filename: "filename.jpg"
filecontent: base64 encoding of file
I am using my userid as the contextid - I'm usnsure whether this is correct due to lack of documentation. When I post this I receieve the error:
{"exception":"moodle_exception","errorcode":"nofile","message":"File not specified"}
I have looked at where core_files_upload is defined in "moodle/files/externallib.php" and this error message is generated when filecontent is not present.
I have tried posting to a test script and I can successfully create the image on the Moodle server based on the base64 encoding eg:
<?php
file_put_contents('MyFile.jpg', base64_decode($_POST['filecontent']));
Can anyone shed light on why I am being unsuccessful uploading to Moodle?
Is the contextid the userid of the user doing the upload?