Hi,

I've been working on a module to allow users to have a form which allows other users to send them files which are sent to their Dropbox account. As there isn't a real API yet (it's in the pipeline), it was simply going to be a one-way form.

I was then pointed to this module as a possible place for this function to fit in. I've browsed the source code, but I'm still not sure I get it; using the API's from this module, could I create a "storage" module which would take the result from a file upload and pass it off to Dropbox? Do the MediaMover API's expect that a storage service has proper API's for retrieval and so on? And are the API's bound to node objects?

Thanks!

Comments

deviantintegral’s picture

I've gone ahead and posted a module for this: http://drupal.org/project/dropbox/.

arthurf’s picture

Hi-

First- yes- create a storage or complete operation that moves the file to dropbox. The one issue is making sure that when the file is displayed on the node (see below) that the link is correct- you will need to either take charge of providing the theming aspects, or modify the drupal files table (not always the best idea).

Secondly- the API question- Media Mover does not expect anything outside of a returned file path from a module. You can modify the file array as it gets passed around, but the only thing you have to pass back is a file path. So pretty much, Media Mover doesn't care about Dropbox's APIs at all.

Thirdly- node objects- Media Mover is not bound to nodes. It can use nodes to harvest and store too, but it does not have to use them. See the MM Dir module or the MM FTP module for examples of these. MM Dir is probably the simplest one to look at.

If you'd like help with this, I'd be glad to assist you- it'd be cool functionality to have on board!

arthurf’s picture

Here's some proto code. You'd still need to build your configuration forms (I'm not sure what you'd need for those) and integrate in the actual push of files to dropbox, but if you already have that built for your module, integrating this will be simple.

<?php
/**
 * Implementation of media_mover hook
 * @param $op is the operator to return
 * @param $action is which action is being called
 * @param $verb is the verb being run
 * @param $configuration is the specific configuration saved for the action for this configuration
 * @param $file is the file in use
 * @param $job is the full configuration data currently running
 */
function mm_dropbox_media_mover($op = null, $action = null, $configuration = null, &$file=array(), $job = null, $nid = null ) {
  switch ($op) {

    // give your module a distinct name
    case 'name':
      return "Media Mover DropBox module";
    break;

    // defines the actions that this module does
    // these are numbered for easy identification of what
    // action is being called
    case 'actions':
      return array(
        'storage' => array( 2 => t('Store files on DropBox'),),
        'complete' => array( 3 => t('Store files on DropBox'),),
      );
    break;

    // create edit configuration option set
    case 'config':
      return mm_dir_config_storage($configuration);
    break;

    // functions called on storage op
    case 'storage':
    case 'complete':
      return mm_dropbox_send($file, $configuration, $action);
    break;

    // implements a delete call from media mover
    case 'delete':
      return mm_dropbox_delete($file, $configuration);
    break;

  }
  return;
}

?>
<?php
/**
 * Sends a file to dropbox. User/login data is stored in $configuration
 *
 * @param array $file
 * @param array $configuration
 * @param int $action
 * @return string
 */
function mm_dropbox_send ($file, $configuration, $action) {
  // get the path to the file to operate on. We need this
  // to pass out of the function
  $file_path = media_mover_api_config_current_file($file);
  // send file to drop box
     .... your operations here

  // get the sent file path
  
  return $file_path
}

?>