Content download via webservice

Content download via webservice

by Giorgio Riva -
Number of replies: 4
Hi to all, I have a problem with content download via web service (token authentication). I successfully wrote four external functions in order to: - list category tree - list courses in category - list resources in course - get resources details I'm missing the last thing, how to let the users download/see the content of resources. In the last function I'm able to retrieve the url of the file related to resource (legacy file) but it doesn't work, because download requires web authentication (different from token authentication). What is the right way to write it? Performing a fake web authentication inside the webservice functions or is there a way to return the file as a param of a function (like for file upload function)? I hope that my situation is clear, using token authentication users cannot download file directly using the url linking the file but I cannot figure out how to return the file via webservice. Thanks in advice and sorry for my poor english.
Average of ratings: -
In reply to Giorgio Riva

Re: Content download via webservice

by Sahil Rally -

Please let me know the external function if you have achieved downloading the content . I require the same. thanks

In reply to Giorgio Riva

Re: Content download via webservice

by Sergio Hernández -

Hi

You can add the token to the url

Example

moodle/webservice/pluginfile.php/22/mod_resource/content/1/afile.pdf?forcedownload=1&token=atoken

Regards

Sergio

Average of ratings: Useful (1)
In reply to Sergio Hernández

Re: Content download via webservice

by roc mehra -

Hi,

I have same problem. what token should be use for downloading the content.I am getting this result when itrying to download content. What should i do.

 

{"error":"Sorry, the requested file could not be found","stacktrace":null,"debuginfo":null,"reproductionlink":null}
In reply to Giorgio Riva

Re: Content download via webservice

by Json Chau -

The first you must use the function "core_course_get_content".

This function will return a lot of fileutl from a course.

Ex: 1 file URL

http://<your moodle>/webservice/pluginfile.php/37/mod_resource/content/1/BTXDPMHDT.pdf?forcedownload=1

and then, You just add a token into URL

http://<your moodle>/webservice/pluginfile.php/37/mod_resource/content/1/BTXDPMHDT.pdf?forcedownload=1&token=6a18222af87608fe4d2ab2ca7ab1f49a