Index: modules/blogapi.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blogapi.module,v retrieving revision 1.5 diff -u -r1.5 blogapi.module --- modules/blogapi.module 22 Dec 2003 11:28:07 -0000 1.5 +++ modules/blogapi.module 26 Feb 2004 17:49:18 -0000 @@ -225,7 +225,41 @@ } function blogapi_new_media_object($req_params) { - return blogapi_error('not implemented'); + $params = blogapi_convert($req_params); + + $user = blogapi_validate_user($params[1], $params[2]); + if (!$user->uid) { + return blogapi_error($user); + } + + $name = $params[3]['name']; + $data = $params[3]['bits']; + + if (!$data) { + return blogapi_error(t("No data sent")); + } + + if (!valid_input_data($name, $data)) { + return blogapi_error(t("File upload failed: invalid data.")); + } + + // Create a temporary version first. + $tempdir = variable_get('file_directory_temp', (PHP_OS == 'WINNT' ? 'c:\\windows\\temp' : '/tmp')); + $temp = tempnam($tempdir, 'blogapi'); + if (!$fp = fopen($temp, 'w')) { + return blogapi_error(t("Error opening temporary file.")); + } + fwrite($fp, $data); + fclose($fp); + + // Move the file to the final location. + if (!file_move($temp, $name, true)) { + return blogapi_error(t("Unable to store file.")); + } + + // Return the successful result. + $result = new xmlrpcval(array('url' => new xmlrpcval(file_create_url($name), 'string')), "struct"); + return new xmlrpcresp($result); } function blogapi_get_category_list($req_params) {