There are several Amazon Web Services related Drupal projects like: Amazon S3, Storage API, Amazon Web Services, Creeper, Media Mover, some others. But none of them are ready to use out of the box to upload files via filefield to Amazon S3. At least, for non-coder Drupal users it is comparatively hard to configure to make it work.

So I decided to offer 50USD for who can make my Drupal site to work with Amazon S3 service.

Thanks for attention.

Comments

jvizcarrondo’s picture

I add hook_form_alter and hook_nodeapi in amazon_s3.module (Amazon S3 module).
below the hook
amazon_s3.module

function amazon_s3_form_alter(&$form, $form_state, $form_id) {
  global $user;
  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
    $type = $form['#node']->type;
    $band_fields = 0;
    $list_fields = content_fields();
    foreach ($list_fields as $a=>$b) {
      if ($b['type_name']==$type && $b['type']=='filefield') {
        $band_fields = 1;
      }
    }
    if ($band_fields) {
      $bucket_names = amazon_s3_get_buckets();
      $bucket_name[0] = t('None');
      foreach ($bucket_names as $bucket_name) {
        $bucket_name[$bucket_name] = $bucket_name;
      }
      $form['box'] = array(
        '#type' => 'fieldset',
        '#title' => t('Upload Cck Files in amazon 3'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form['box']["bucket"] = array(
        '#type'=>'select',
        '#title'=>"Add Amazon S3 to bucket",
        '#options'=>$bucket_name,
      );
      $form['box']['acl'] = array(
        '#type' => 'select',
        '#title' => t('Access Control'),
        '#options' =>amazon_s3_acl_options(),
      );
    }
  }
}

function amazon_s3_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':
    if ($node->bucket && $node->acl) {
      $bucket = $node->bucket;
      $acl = $node->acl;
      $list_fields = content_fields();
      global $base_path;
      $s3 = amazon_s3_get_instance();
      foreach ($list_fields as $a=>$b) {
        if ($b['type_name']==$node->type && $b['type']=='filefield') {
          foreach($node->$b['field_name'] as $c=>$d) {
            $upload_cck_filepath = $base_path . $d['filepath'];
            $object_filename = $d['filename'];
            if (trim($upload_cck_filepath) != '') {
              $success = $s3->putObjectFile( $upload_cck_filepath, $bucket, $object_filename, $acl);
              if ($success) {
                $message = t('Succesfully uploaded the file %filename to the bucket %bucket.', array('%filename' => $object_filename, '%bucket' => $bucket));
                drupal_set_message($message);
              } else {
                $message = t('Failed to upload the file %filename to the bucket %bucket.', array('%filename' => $object_filename, '%bucket' => $bucket));
                drupal_set_message($message, 'error');
              }
            }
          }
        }
      }
    }
    break;
  }

}

waiting for help in some way for what you want
Juan

hypertext200’s picture

In the video module we already done that ;o), but that is only for videos :P LOL

Heshan Wanigasooriya
Github

yngens’s picture

Do you know if video module can also accept pictures and audio files in its videofield? The problem in my case is that I want to use only one filefield for uploading pictures, videos and audios and just filefield itself does this perfectly.

yngens’s picture

jvizcarrondo, thanks for prompt reply. tried your code, alas, no success. what am i doing wrong? have you successfully uploaded to Amazon S3 yourself?

yngens’s picture

gives the following on node creating page:

warning: Invalid argument supplied for foreach() in /usr/drupal/drupal6/includes/form.inc on line 1430.
jvizcarrondo’s picture

i change a little code ($bucket_name[$bucket_name] in hook_form_alter, and $base_path . $d['filepath'] in hook_nodeapi:

function amazon_s3_form_alter(&$form, $form_state, $form_id) {
  global $user;
  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
    $type = $form['#node']->type;
    $band_fields = 0;
    $list_fields = content_fields();
    foreach ($list_fields as $a=>$b) {
      if ($b['type_name']==$type && $b['type']=='filefield') {
        $band_fields = 1;
      }
    }
    if ($band_fields) {
      $bucket_names = amazon_s3_get_buckets();
      $bucket_nameL[0] = t('None');
      foreach ($bucket_names as $bucket_name) {
        $bucket_nameL[$bucket_name] = $bucket_name;
      }
      $form['box'] = array(
        '#type' => 'fieldset',
        '#title' => t('Upload Cck Files in amazon 3'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form['box']["bucket"] = array(
        '#type'=>'select',
        '#title'=>"Add Amazon S3 to bucket",
        '#options'=>$bucket_nameL,
      );
      $form['box']['acl'] = array(
        '#type' => 'select',
        '#title' => t('Access Control'),
        '#options' =>amazon_s3_acl_options(),
      );
    }
  }
}
function amazon_s3_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':
    if ($node->bucket && $node->acl) {
      $bucket = $node->bucket;
      $acl = $node->acl;
      $list_fields = content_fields();
      global $base_path;
      $s3 = amazon_s3_get_instance();
      foreach ($list_fields as $a=>$b) {
        if ($b['type_name']==$node->type && $b['type']=='filefield') {
          foreach($node->$b['field_name'] as $c=>$d) {
            $upload_cck_filepath = realpath($d['filepath']);
            $object_filename = $d['filename'];
            if (trim($upload_cck_filepath) != '') {
              $success = $s3->putObjectFile( $upload_cck_filepath, $bucket, $object_filename, $acl);
              if ($success) {
                $message = t('Succesfully uploaded the file %filename to the bucket %bucket.', array('%filename' => $object_filename, '%bucket' => $bucket));
                drupal_set_message($message);
              } else {
                $message = t('Failed to upload the file %filename to the bucket %bucket.', array('%filename' => $object_filename, '%bucket' => $bucket));
                drupal_set_message($message, 'error');
              }
            }
          }
        }
      }
    }
    break;
  }

}

waiting for help in some way for what you want
Juan

yngens’s picture

This worked smoothly. However, I needed not only upload files, but be able to use them in displaying nodes. And for now it uses local files, which I actually do not need at all to save place if Amazon S3 is going to work.

May I contact you via your contact form to discuss all these details?

jvizcarrondo’s picture

I sent a email in your contact form

maddy121’s picture

I'm also looking at a similar function for the website, upload images to Amazon s3 and serve it through s3 on the nodes.

Just wondering, if you were able to achieve this.

yngens’s picture

Yep, after hiring an experienced in S3 developer, we have solved this problem. So now we have fully functional picture upload web-project, which is served by Amazon S3.

maddy121’s picture

Thanks for the reply. Are you willing to share the module? If yes, please contact me with a price that seems reasonable for the level of effort.

ionut.alexuc’s picture

Once you have the pictures on amazon s3, you can use the CDN module (http://drupal.org/project/cdn)
It does what you want.