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.'));
  }
}

CommentFileSizeAuthor
#2 file_service.module.patch1012 bytespsy
#2 file_service.inc_.patch761 bytespsy

Comments

marcingy’s picture

Status: Active » Postponed (maintainer needs more info)

Please provide a patch file.

psy’s picture

StatusFileSize
new761 bytes
new1012 bytes

Not sure if I have done this patches correctly. :)

kylebrowning’s picture

Status: Postponed (maintainer needs more info) » Needs review

Status: Needs review » Needs work

The last submitted patch, file_service.inc_.patch, failed testing.

kylebrowning’s picture

Version: 6.x-2.2 » 6.x-2.x-dev
Status: Needs work » Needs review
kylebrowning’s picture

#2: file_service.module.patch queued for re-testing.

kylebrowning’s picture

#2: file_service.inc_.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, file_service.inc_.patch, failed testing.

kylebrowning’s picture

Status: Needs work » Closed (won't fix)

This has been fixed in 3.x. 2.x is feature frozen.