I've been trying to create and update users and their pictures through REST calls using the services module. So far, I've got creating and updating users to work, but creating files to set their profile pictures still doesn't work.
I try to do a POST request to my API endpoint (http://www.domain.com/api/api_name/file), with the following data:
$data = array(
'file' => base64_encode($file),
'filename' => $filename,
'filepath' => 'public://' . $filename
);
I POST this using CURL, with the exact same settings (apart from the API endpoint) as I'm using to create a user, which is working. However, I'm getting a HTML 500 as a response, with no response contents otherwise. The following error is logged in the Drupal error log:
Notice: Undefined property: stdClass::$fid in file_entity_access() (regel 1661 van /home/enschede/domains/aegee-enschede.nl/public_html/sites/all/modules/file_entity/file_entity.module).
The function that it errors on, file_entity_access
, says that its $file
parameter will either be an object, or a string with the file type (e.g. "image"
) if it is a create action. Apparently, it receives an object, so the create action is not executed properly on the server.
However, at this point I'm stuck. I can't find where these calls are coming from on the server, and I can't find anything I should change in the POST request. The fields I'm posting are the same as a tutorial I've followed. I'm posting the following fields to create a user, with the exact same CURL options otherwise:
$initialData = array(
'name' => 'test.user',
'mail' => '[email protected]',
'pass' => 'waytoolongboguspassword',
'status' => 1
);