Quantcast
Channel: Web services
Viewing all articles
Browse latest Browse all 2364

How do I upload files to an assignment without removing previous submissions

$
0
0
by Sujit Kumar.  

I upload a file to Moodle using this request.

[POST] https://{{baseUrl}}/webservice/upload.php?token={{token}}&itemid=0

Which gives this response on success.

[
    {
        "component": "user",
        "contextid": 16,
        "userid": "4",
        "filearea": "draft",
        "filename": "floppy.img",
        "filepath": "/",
        "itemid": 376760955,
        "license": "allrightsreserved",
        "author": "John Doe",
        "source": "O:8:\"stdClass\":1:{s:6:\"source\";s:10:\"floppy.img\";}"
    }
]

I then use the itemid obtained from the above response to add it as an assignment submission with this request.

[POST] https://{{baseUrl}}/webservice/rest/server.php?wstoken={{token}}&moodlewsrestformat=json&wsfunction=mod_assign_save_submission&plugindata[files_filemanager]=376760955&assignmentid=1

This works perfectly except it removes any previous files that have been added to the assignment. This issue will be resolved if I can get the itemid that is already linked to the assignment. Is there a function that gives the file manager item id of an assignment? It wasn't available in mod_assign_get_submission_status.

This is the response for mod_assign_get_submission_status.

{
    "lastattempt": {
        "submission": {
            "id": 1,
            "userid": 4,
            "attemptnumber": 0,
            "timecreated": 1643702568,
            "timemodified": 1643702584,
            "status": "submitted",
            "groupid": 0,
            "assignment": 1,
            "latest": 1,
            "plugins": [
                {
                    "type": "file",
                    "name": "File submissions",
                    "fileareas": [
                        {
                            "area": "submission_files",
                            "files": [
                                {
                                    "filename": "floppy.img",
                                    "filepath": "/",
                                    "filesize": 512,
                                    "fileurl": "https://sandbox.moodledemo.net/webservice/pluginfile.php/46/assignsubmission_file/submission_files/1/floppy.img",
                                    "timemodified": 1643702584,
                                    "mimetype": "application/octet-stream",
                                    "isexternalfile": false
                                }
                            ]
                        }
                    ]
                },
                {
                    "type": "comments",
                    "name": "Submission comments"
                }
            ]
        },
        "submissiongroupmemberswhoneedtosubmit": [],
        "submissionsenabled": true,
        "locked": false,
        "graded": false,
        "canedit": true,
        "caneditowner": true,
        "cansubmit": false,
        "extensionduedate": null,
        "blindmarking": false,
        "gradingstatus": "notgraded",
        "usergroups": []
    },
    "warnings": []
}

Viewing all articles
Browse latest Browse all 2364

Trending Articles