I am new to CiviCRM and did not find any answer to this.
I have a form on a Drupal page, and want to give ability to upload an image file in both Drupal and CiviCRM from within this form.
I use the "Attachment" api function. When saving the Drupal node, I call civicrm_api3('Attachment', 'create', params) and pass file params as well as entity_id and custom field_name as explained in the api explorer. The CiviCRM field is a file custom field and the entity is an event.
Here is the code I use :
$result = civicrm_api3('Attachment', 'create', array(
'debug' => 1,
'sequential' => 1,
'name' => $file->filename,
'mime_type' => $file->filemime,
'entity_id' => $event_id,
'field_name' => $field_name,//custom_14
'url' => file_create_url($file->uri),
'path' => drupal_realpath($file->uri),
));
I finally catch this error (look at {main} at the end):
20 {main}
[is_error] => 1
[error_message] => Failed to run permission check: Unrecognized target entity table (civicrm_event)
)
Guess I missed something, but what ? Any suggestion ?
Thanks for your help
Philippe