Pertama-tama, pastikan di titik akhir Anda mengaktifkan File -> Buat sumber daya.
Dan di "sisi klien" saya melakukan sesuatu seperti ini:
/**
* 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;
}
Saya melakukan ini dari Drupal lain, dan untuk Drupal 6, port kode ke D7 harus mudah, dan saya pikir Anda mendapatkan ide umum tentang bagaimana melakukannya.