Can't get files

Can't get files

by Penyo Rusev -
Number of replies: 8

Hello. I create my webservice but I can't get files with it.
I use http://MyMoodleURL/webservice/rest/server.php?wstoken=UserForMyWebServiceToken&wsfunction=core_files_get_files&component=mod_resource

I tried with component=user and filearea=content and filearea=draft
but no result. Where is my lapse?
Thank you!

Average of ratings: -
In reply to Penyo Rusev

Re: Can't get files

by Penyo Rusev -

I have other question. Is any chanse to get files with webservice's function and convert it from my moodle server?

In reply to Penyo Rusev

Re: Can't get files

by Bill Antonia -

This is one of those annoying little problems where you have a call but cannot get all the information for the call without extracting it directly from the database first such as the contextid etc.

There are 6 parameters after the initial token and webservice name, all which are required.

I know you don't want to go to the database directly but you will find the fields in table mdl_files.

What you get in the response is a URL which you can use to download the file.

Required fields are:

contextid= int
component= string
filearea= string
itemid= int
filepath= string
filename= string
In reply to Bill Antonia

Re: Can't get files

by Penyo Rusev -

Thanks for your help!
Then is unable to get all the files without having access to the database?

And can I get this fields from other webservice's function?

In reply to Bill Antonia

Re: Can't get files

by Penyo Rusev -

Now I tried with
http://MySite/webservice/rest/server.php?wstoken=MyToken&wsfunction=core_files_get_files&contextid=5&component=user&filearea=draft&itemid=667022705&filepath=&filename=a.exe

But no result... My Filepath is empty, because in the db is '\' value.

In reply to Bill Antonia

Re: Can't get files

by Penyo Rusev -

I get fileinfo with this:
http://MySite/webservice/rest/server.php?wstoken=MYToken&wsfunction=core_course_get_contents&courseid=4

and have all files from course. After I try to download, using 'fileurl' like:
http://MYSite/webservice/pluginfile.php/47/mod_resource/content/1/examp.pptx?forcedownload=1

but see this:

{"error":"A required parameter (token) was missing","stacktrace":null,"debuginfo":null,"reproductionlink":null}


How to get the file?

In reply to Penyo Rusev

Re: Can't get files

by Penyo Rusev -

Where must to post Token i this url? I think, that the url which I get from core_course_get_contents is ready for download file...

In reply to Penyo Rusev

Re: Can't get files

by Jérôme Mouneyrac -
Hi Penyo,
Moodle ws process currently doesn't recommend downloading file by web services. You can retrieve file info with some function like core_course_get_courses_content that will return to you the url to download the file (you'll need to edit it to add your token).

Note that to download files, there is a Moodledocs: http://docs.moodle.org/dev/Web_services_files_handling (you'll find demo client too to download files)

Cheers,
Jerome
In reply to Jérôme Mouneyrac

Re: Can't get files

by Penyo Rusev -

Hello! I tried to get files url with

http://MySite/webservice/rest/server.php?wstoken=MYToken&wsfunction=core_course_get_contents&courseid=4

and when I get file url like this :

http://MYSite/webservice/pluginfile.php/47/mod_resource/content/1/examp.pptx?forcedownload=1

I see this error:

{"error":"A required parameter (token) was missing","stacktrace":null,"debuginfo":null,"reproductionlink":null}

So, where to put token in file url? I tried with http://MYSite/webservice/pluginfile.php/47/mod_resource/content/1/examp.pptx?forcedownload=1?token=MYTOKEN   but no result...

Thanks!