Web service image profile

Re: Web service image profile

by Aaron Leggett -
Number of replies: 0

Hey Andrea,

I did run into this issue a while back where we where updating the profile picture from a Tablet App. I've attached the web-service side of the code below for you to look through.

Basically I base64 encoded the image before passing it to the web-service. Not the best way to do it but maybe you will be able to advance from the code I am using below.


if($USER->id != $userid){
    return array('msg'=>'CannotUploadAnotherUsersPicture');
    //throw new moodle_exception('CannotSendSupportRequestAsOtherUser');
}

require_once('../../lib/gdlib.php');
//change to $CFG->libdir

$filePath = $CFG->dataroot."/temp/webservices";
$fileName = $USER->id."_".time().".jpg";
$fullFilePath = $filePath."/".$fileName;

//check if webservices folder exists in temp data dir
if(!file_exists($filePath)){
    mkdir($filePath, 0777);
}

//write file to server (/webservice/xmlrpc)
$ifp = fopen( $fullFilePath, "wb" ); 
fwrite( $ifp, base64_decode( $base64image ) ); 
fclose( $ifp );

//set file as user image
$context = context_user::instance($userid);
$value = process_new_icon($context, 'user', 'icon', 0, $fullFilePath);

//remove file from xmlrpc folder
unlink($fullFilePath);

if($value == false){
    return array('msg'=>'ERROR = '.$fullFilePath);
}

return array('msg'=>$value);