I ran into some issues with using file.get service to retrieve the fid and other info from uploaded files. The problem is file.get also sends back the encoded binary data. I cant be bothered writing a patch but my solution is under.
I believe this should be rolled into Services. I know an issue was raised about this in v1.x of Services
In file_service.module add to the array in file_service_service function
// file.getInfo
array(
'#method' => 'file.getInfo',
'#callback' => 'file_service_get_info',
'#access callback' => 'file_service_get_access',
'#file' => array('file' => 'inc', 'module' => 'file_service'),
'#args' => array(
array(
'#name' => 'fid',
'#type' => 'int',
'#description' => t('A file ID.'),
),
),
'#return' => 'array',
'#help' => t('The file data except the binary data.')
),
And in file_service.inc add the file_service_get_info function. This is the same as file_service_get but with the binary removed.
/**
* Get all elements from a given file
*
* @param $fid
* Number. File ID
* @return
* Array. All elements for a given file except the data
*/
function file_service_get_info($fid) {
if ($file = db_fetch_array(db_query('SELECT * FROM {files} WHERE fid = %d', $fid))) {
// removed the retrieval of teh binary data in the next 4 lines
// $filepath = file_create_path($file['filepath']);
// $binaryfile = fopen($filepath, 'rb');
// $file['file'] = base64_encode(fread($binaryfile, filesize($filepath)));
// fclose($binaryfile);
return $file;
}
else {
return services_error(t('There is no file with the given ID.'));
}
}
Comments
Comment #1
marcingy commentedPlease provide a patch file.
Comment #2
psy commentedNot sure if I have done this patches correctly. :)
Comment #3
kylebrowning commentedComment #5
kylebrowning commentedComment #6
kylebrowning commented#2: file_service.module.patch queued for re-testing.
Comment #7
kylebrowning commented#2: file_service.inc_.patch queued for re-testing.
Comment #9
kylebrowning commentedThis has been fixed in 3.x. 2.x is feature frozen.