drupal-7drupal-services

Registration with profile picture using services in Drupal


I've been trying to upload a user profile picture during the user registration using Service 3 and so far I haven't had any luck. I tested passing a hard coded fid in the field "picture" and also tried to pass the fields "filemime", "filename", etc. and it didn't work neither. Any idea about what fields I need to populate?

I guess it must be related to this post Using Drupal Services and DIOS SDK for setting user picture in iOS app but it doesn't have and answer neither.


Solution

  • I use following code -

    //Picture is first uploaded from ios using file service and fid is passed in $data object
    $file_contents_object = file_load($data->picture_fid);
    $file_contents_array['fid'] = $file_contents_object->fid;
    $file_contents_array['uid'] = $file_contents_object->uid;
    $file_contents_array['filename'] = $file_contents_object->filename;
    $file_contents_array['uri'] = $file_contents_object->uri;
    $file_contents_array['filemime'] = $file_contents_object->filemime;
    $file_contents_array['filesize'] = $file_contents_object->filesize;
    $file_contents_array['status'] = $file_contents_object->status;
    $file_contents_array['timestamp'] = $file_contents_object->timestamp;
    $file_contents_array['rdf_mapping'] = $file_contents_object->rdf_mapping;
    //use your cck field here
    $user_obj->field_user_profile_picture['und'][0] = $file_contents_array;
    

    Hope this will help.