Wondering if there's a proper procedure for doing this? I've got a site with a ton of images/image cache versions that I'd love to switch over to my Storage API Amazon S3 container.

I've got two containers setup for a class, an initial local filesystem one in the same directory as my original sites/default/files dir, and then an Amazon S3 one.

Is it possible to get Storage API to recognize these existing images and their imagecache versions?

Comments

cgdrupalkwk’s picture

Check out https://drupal.org/project/storage_api_populate. It appears to be a work in progress but is aiming to do what you've described.

dantodd’s picture

Issue summary: View changes

Is there an update on this?

The module referred to by @cgdrupalkwk has no files and no activity for some time.

Andre-B’s picture

dantodd check the repository, might help you start: http://drupalcode.org/project/storage_api_populate.git/tree/refs/heads/m...

jiv_e’s picture

Try something like this... quite ad hoc, but works for me.

Put this code in your file migration class and change the $field_name variable to match your file field name.

  public function complete($entity, stdClass $row) {
    $field_name = 'field_your_field_name';
    $scheme = file_uri_scheme($entity->uri);
    $target = file_uri_target($entity->uri);
    $storage_core_bridge_uri = preg_replace('/^' . $scheme . '/', storage_core_bridge_field_scheme($field_name), $entity->uri);
    $options = array(
      'source_uri' => $entity->uri,
      'filename' => $target,
      'keep_source_uri' => FALSE,
    );
    try {
      // Add to Storage API.
      $storage = storage_core_bridge_field_selector($field_name)->storageAdd($options);
      db_insert('storage_core_bridge')
        ->fields(array(
          'storage_id' => $storage->storage_id,
          'uri' => $storage_core_bridge_uri,
        ))
        ->execute();

      // Update File URI.
      $entity->uri = $storage_core_bridge_uri;
      $saved_file = file_save($entity);
    }
    catch (StorageException $e) {
      $context['results']['failed'][] = $entity->uri;
      $message = 'Failed adding file @fid from field @field_name to storage api with exception @exception.';
      $variables = array(
        '@fid' => $entity->fid,
        '@field_name' => $field_name,
        '@exception' => $e->getMessage(),
      );
      watchdog('storage_api_populate', $message, $variables, WATCHDOG_ERROR);
    }
  }
Perignon’s picture

Assigned: Unassigned » Perignon

This is a very valid request to migrate data. Worth considering and potentially documenting as an option for people coming from a local file system.

Perignon’s picture

I added the module identified in #1 as a related module on the project page of Storage API. I see there was some recent activity on that module by the maintainers.

jonhattan’s picture

Status: Active » Fixed

Yep, I'm the new maintainer. Please report any bug or request .. to the module's issue queue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.