Using web service to upload file to an existing activity module?

Using web service to upload file to an existing activity module?

by muzaki azami -
Number of replies: 7

I'm wondering if it is possible for moodle to receive files from external service, and 'assign' it to an activity module that already exists.

To put into perspective, my activity module's flow is : User creates an activity module (and attach a file in it) -> the file is sent to a webservice using adhoc task after the user saved the file -> the webservice processes the file -> the webservice then uploads the processed file to the activity module that the user has created.

I've tried looking into https://docs.moodle.org/dev/Web_services_files_handling but it confused me...

Thank you in advance.

Average of ratings: -
In reply to muzaki azami

Re: Using web service to upload file to an existing activity module?

by muzaki azami -
Anyone that can help me with this subject? Or it's an unspoken rule that it is not possible....?
In reply to muzaki azami

Re: Using web service to upload file to an existing activity module?

by Benjamin Ellis -
Picture of Particularly helpful Moodlers
Hi,

It is possible though your workflow seems a little confusing. Why doesn't your ad-hoc task just send the file and then wait for the file to be sent back? Otherwise, you have to define a web service user, assign capabilities etc for the external service.  The upload of files via external service functionality is done in two steps - see attached extract from my book 'Introduction to Moodle 3.9+ Plugin Development' that might help you understand better.

Cheers



Average of ratings: Useful (1)
In reply to Benjamin Ellis

Re: Using web service to upload file to an existing activity module?

by muzaki azami -
Thank you for the reply! I will look into the book excerpt you've sent.

And to answer your question, I did consider doing that but I thought processing a 2hr long vid would take some time, and the call from the adhoc task to this processing external service is done through curl (I'm not sure what else I could use to send JSON + file)
In reply to muzaki azami

Re: Using web service to upload file to an existing activity module?

by Benjamin Ellis -
Picture of Particularly helpful Moodlers
Ok, makes a bit of sense. You could consider having another adhoc or even scheduled task that can retrieve the processed file instead thus avoiding the need to use a web service to send back the file.
Average of ratings: Useful (1)
In reply to Benjamin Ellis

Re: Using web service to upload file to an existing activity module?

by muzaki azami -
Interesting! I didn't really thought of a task that can retrieve the processed file from the remote webservice.

Considering the size of the file being processed and supposedly passed through so many webservices, I guess a scheduled task would be preferable?

Also, is setting up for Moodle's webservice feature really that complicated in your opinion? I'd love to hear your thoughts about it, since this project is my thesis and I think it's better for me to explain why I opted for one method and not the other.
In reply to muzaki azami

Re: Using web service to upload file to an existing activity module?

by Benjamin Ellis -
Picture of Particularly helpful Moodlers

Hi

If you navigate to Site administration->Plugins->Web services->Overview (/admin/settings.php?section=webservicesoverview) in your Moodle, you will see there is between 5 and 11 steps to be taken by the site admin to set up an external service depending on the scenario. Some of the steps can be handled programmatically but others would require providing instructions for the administrator. I have a step by step example of developing an external service in my book and if you are OK with it, I can send you the relevant sample subchapter but I would rather send that to you by email.

I am originally a Perl developer and I keep to its popular KISS (Keep It Simple Stupid) principle whenever I consider projects.

Cheers


Average of ratings: Useful (1)
In reply to Benjamin Ellis

Re: Using web service to upload file to an existing activity module?

by muzaki azami -

Yeah, I have looked up the setup for it in Site Adminstration page, but I'm quite unclear what steps I should take and how to "expose" the specific Activity Module that would receive the file from the external service. That's what holding me back from choosing it hahaha, if the Ad-hoc Task method turns out to be easier (for me and for the users), I would choose it easily.


Feel free to email me at : dank.knyte@gmail.com if you would, sir.