hook_services_services create - what would the arg be for image data

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
ajlow's picture

I've created a REST server user Services 7.x-3.1.

I want to be able to accept an image. My question, how should I set up my create service?

Currently I have this for my hook_services_resources:

  'create' => array(
    'help' => 'Creates an issue',
    'file' => array('file' => 'inc', 'module' => 'issue'),
    'callback' => '_issue_create',
    'access arguments' => array('issue service create'),
    'access arguments append' => FALSE,
    'args' => array(
      array(
        'name' => 'data',
        'type' => 'struct',
        'description' => 'The issue object',
        'source' => 'data',
        'optional' => FALSE,
      ),
    ),

and this:

    function _issue_create($data) {

    if (isset($data) &&  is_array($data)) $data=(object) $data;

    unset($data->id);
    $data->created = time();
    $data->modified = time();

    if (!isset($data->email)) {
      return services_error('Missing issue attribute email address', 406);
    }

  if (!isset($data->details)) {
    return services_error('Missing issue attribute details', 406);
  }

  if (!isset($data->image)) {
    return services_error('Missing issue attribute image', 406);
  }
 
  issue_write_issue($data);

  return (object)array(
    'id' => $data->id,
    'uri' => services_resource_uri(array('issue', $data->id)),
  );
}

however I keep getting the "Missing issue attribute image" 406 error due to image not being set in my $data.

Do I need to add in an extra arg for my create service?

If so, what should it be?

Thank you for your help in this matter.

Comments

Figured it out $_FILES!

ajlow's picture

finally realised I can use the $_FILES variable. All good.