まず、エンドポイントでファイル->リソースの作成を有効にします。
そして「クライアント側」で私はこのようなことをしました:
/**
* Upload a file using services 3.X
*
* @param the path of the local file
* @return bool|int the fid of the file.
*
*
* With the fid you can attach this file in the node object before to be send.
* ej.
* $node->title = 'My remote node';
* $fid = node_upload_image('/The_path/to_the/local_file.jpg');
* $node->file_field[0] = array(
* 'fid' => $fid,
* 'list' => 1,
* 'data' => array()
* );
* // Other fields related with the node.
* ...
*
* // Sending the node.
* $data = http_build_query($node, '', '&');
* $response = drupal_http_request('myremotesite.com'. '/node', array(
* 'Accept' => 'application/json',
* 'Cookie' => 'auth_cookie_info'
* ), 'POST', $data);
*
* Done.
*/
function node_upload_image($image_path) {
$file = array(
'filesize' => filesize($image_path),
'filename' => basename($image_path),
'file' => base64_encode(file_get_contents($image_path)),
'uid' => 1 // This should change it by the user who use the service.
);
$data = http_build_query($file, '', '&');
$response = drupal_http_request('myremotesite.com/myservice-endpoint' . "/file", array('Accept' => 'application/json', 'Cookie' => 'auth_cookie_info'), "POST", $data);
if ($response->code == 200) {
return json_decode($response->data)->fid;
}
$this->error = $response->status_message;
return false;
}
私は別のDrupalからこれを行いましたが、Drupal 6の場合、コードをD7に移植するのは簡単なはずです。