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

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

by Sujit Kumar -
Number of replies: 1

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": []
}
Average of ratings: Useful (1)
In reply to Sujit Kumar

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

by Sujit Kumar -

I was told the moodle mobile app gets the submission status, parses the file details out of the response and then merges the new and existing file info into an array, which is then sent to the webservice. Can someone show me how this is done?

This line led me to believe the app downloads and re-uploads every single file, I really hope that's not the case.