General developer forum

 
 
Picture of yang bu
really need some help about core_files_upload this api....thank you!
 

I need to upload some file to moodle......yeah, but in the forum, I've found a little information about that, and now I've made my url like this:

myhost/moodle/webservice/rest/server.php
?wstoken=mytoken&wsfunction=core_files_upload&contextid=1
&component=user&filearea=private&itemid=1
&filepath=/&filename=image.jpg&filecontent=C:/image.jpg

I don't know where the problem is,  when I use it and it always tell a nofile error........truely need some help here...thanks,,guys  .............

 
Average of ratings: -
Picture of Marco Andreatta
Re: really need some help about core_files_upload this api....thank you!
 

Hi,

It looks like you want to upload your file to some user's private area.

I've found more useful to use core moodle API instead of web services.

Please, take a look to the following code snippet:

$fs = get_file_storage();

$fileinfo = array(
                'contextid' => <contextid for your user>,
                'component' => 'user',
                'filearea' => 'private',
                'itemid' => 0,
                'filepath' => <path of the uploaded file in the private area>,
                'filename' => <path of the uploaded file in the private area>);

$file = $fs->create_file_from_pathname($fileinfo, <path to your current file>);

Hope this helps,Marco.

 
Average of ratings: -
Picture of Marco Andreatta
Re: really need some help about core_files_upload this api....thank you!
 

Well, if you need webservices, I guess you should send functions params through HTTP POST, i.e.:

myhost/moodle/webservice/rest/server.php?wstoken=mytoken&wsfunction=core_files_upload

the other parames (contextid,componet, etc.) being sent through POST:

filecontent should be sent base64 encoded.

I suggest you to take a look to files/externallib.php where moodle upload functions take place.

Hope this helps,

Marco.

 
Average of ratings: -