How to add multiple files to assignment submissions

How to add multiple files to assignment submissions

by Anang Ma`ruf Budiyanto -
Number of replies: 0

So recently I worked with moodle web service. So I want to save user submission and it is saved. But the problem is, the api will remove existing attachment (file(s)) and replace with new one. I am using the mod_assign_save_submission service. The documentation says that file will be attached via plugindata[files_filemanager] and it is only accept integer value (itemid from core_files_upload) and it means that only one file can be attached. So how am i supposed to submit multiple files? Thanks. 

Here is what I've tried


var params = {
    wstoken:'MYTOKEN',
    wsfunction:'mod_assign_save_submission',
    moodlewsrestformat:'json',
}

var data = {
    assignmentid: 4,
    plugindata[onlinetext_editor][text]:'<h1>Hello World</h1>',
    plugindata[onlinetext_editor][format]:1,
    plugindata[onlinetext_editor][itemid]:2,
    plugindata[files_filemanager]:729767390 // id from core_files_upload
}

var conf = {
    method:'POST',
    url: 'https://MY.MOODLE/webservice/rest/server.php',
    header: {
            'Access-Control-Allow-Origin': '*',
            'Accept': 'application/json',
            'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept',
            'Access-Control-Allow-Method': 'GET, POST, OPTIONS, PUT, PATCH, DELETE'
        },
    params: params,
    // convert json to multipart
    data: jsonToFormData(data)
}

await axios(conf)
    .then(r=>{
        console.log(r)
    })
    .catch(e=>{
        console.log(e)
    })

Average of ratings: -