My query is regarding the use of the core_file_upload
function in Moodle within a NestJS application. I've successfully integrated the core_course_create_courses
function, and it's functioning as expected. Now, I'm attempting to upload a file to a course, for which I'm trying to integrate the core_file_upload
function.
Here's the API code
@Post('/upload')
async uploadFileToMoodle(@Body() params: any): Promise<any> {
const courseParams = new URLSearchParams({
wstoken: '2dfc2e7d219295e5d7469562a93b7d94',
moodlewsrestformat: 'json',
wsfunction: 'core_files_upload',
'contextid': params.contextid,
'component': params.component,
'filearea': params.filearea,
'itemid': params.itemid,
'filepath': params.filepath,
'filename': params.filename,
})
const response = await axios.post(
`http://localhost/moodle/webservice/rest/server.php?${courseParams.toString()}`
);
return response.data;
}
The
Here's an example of how I'm passing the data in Postman:
The
filecontent
parameter requires a base64 URL, Am I correct?Here's an example of how I'm passing the data in Postman:
{
"contextid": 2,
"component": "user",
"filearea": "draft",
"itemid": 1,
"filepath": "/",
"filename": "clickHere.png",
"filecontent": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAOQCAIAAABXWfsZAAAAAXNSR0IArs4c6QAAIABJREFUeJzs3Xd8FHX+x/HvzJa0Ta+QSkIaCS2AVAERiaCAK
}
I'm providing actual base64 URL, this is just example.
I'm encountering the following error:
I'm providing actual base64 URL, this is just example.
I'm encountering the following error:
{
"exception": "invalid_parameter_exception",
"errorcode": "invalidparameter",
"message": "Invalid parameter value detected"
}
Could you please assist me in identifying the cause of this issue?
Also, once the file is successfully uploaded to Moodle, how can I link it to a specific course?