我正在尝试开发Moodle Android应用。我使用MoodleREST源代码供我参考。但是此库不提供上传分配的其余代码。我希望能够通过webservice调用从移动客户端上传分配。可以使用webview上传分配,但在这种情况下,用户需要再次登录才能访问上载分配页面。
我在https://moodle.org/mod/forum/discuss.php?d=207875发现了类似的内容。
我是moodle的新手并且还在学习它,所以我的问题可能有点幼稚,所以请耐心等待:)
答案 0 :(得分:0)
看起来moodle web服务中没有现成的解决方案。 Moodle实际上编码了base64中的文件,这给移动设备带来了负担。移动设备没有那么多内存来编码大文件。 Moodle HQ(以及其他方式)发布的Closet解决方案是:https://github.com/moodlehq/sample-ws-clients/blob/master/PHP-HTTP-filehandling/client.php将文件保存为私有文件而不是赋值。您可能必须大幅修改插件。
答案 1 :(得分:0)
使用Moodle网络服务可以将带有文件的提交上传到作业。
首先使用core_files_upload
http://my-moodle-url/moodle/webservice/rest/server.php?wstoken=token_value_xyz&moodlewsrestformat=json&wsfunction=core_files_upload&component=user&filearea=draft&itemid=0&filepath=/&filename=test2.txt&filecontent=TWFuIGlzIGRpc3Rpbmd1aXNoZWQ=&contextlevel=user&instanceid=8
其中:
itemid = 0-心情将生成并返回itemid
或您设置itemid
filecontent-base64编码的文件内容
instanceid-用户ID,其Web服务令牌
示例响应:
{
"contextid": 26,
"component": "user",
"filearea": "draft",
"itemid": 293005570,
"filepath": "/",
"filename": "test3.txt",
"url": "http://my-moodle-url/moodle/draftfile.php/26/user/draft/293005570/test3.txt"
}
您可以使用mod_assign_get_assignments
然后在mod_assign_save_submission
中收到使用的id,在这里为“ 293005570”
http://my-moodle-url/moodle/webservice/rest/server.php?wstoken=token_value_xyz&moodlewsrestformat=json&wsfunction=mod_assign_save_submission&assignmentid=5&plugindata[onlinetext_editor][text]
=some_text_here&plugindata[onlinetext_editor][format]
=1&plugindata[onlinetext_editor][itemid]=521767865&plugindata[files_filemanager]=521767865
这将为此文件添加作业提交。
我只能core_files_upload
和mod_assign_save_submission
使用特定用户的Web服务令牌的问题,即每个用户都需要一个不实际的Web服务令牌。使用webservices用户令牌,我可以进行第一个呼叫:
{
"exception": "moodle_exception",
"errorcode": "nofile",
"message": "File not specified"
}
经过邮递员测试。这可能与以下内容有关:https://tracker.moodle.org/browse/MDL-61276
答案 2 :(得分:0)
要上传文件,我正在通过POST方法使用此API
https:// {YOUR_URL} /webservice/upload.php?moodlewsrestformat=json&wstoken= {WSTOKEN}
并且您必须将以下参数作为FormData传递