Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1065589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:49:27+00:00 2026-05-16T19:49:27+00:00

I would like to call a Ruby script when a user uploads an image

  • 0

I would like to call a Ruby script when a user uploads an image to my Drupal content-type. I have a CCK image field that serves as the main image, and ImageCache takes care of resizing and creating thumbnails for me.

I have a Ruby script that does some transformations to the image, however I don’t exactly know how to call it (no experience with Ruby really). Basically the script applies some image transforms and then generates a new image.

My question is how to call this script from Drupal…is there some sort of hook regarding the CCK image upload that I would hijack?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T19:49:28+00:00Added an answer on May 16, 2026 at 7:49 pm

    ImageField uses the same API as FileField. Therefore, you could add a custom validator for your upload field, which would do some checks on the image (like calling a ruby script).

    I described that some time ago on Drupal.org, see: http://drupal.org/node/546146

    However, for your convenience, here the code.

    First, define a validator for the upload form:

    function example_form_alter(&$form, $form_state, $form_id) {
      if ($form_id != 'ID_OF_YOUR_FORM')
        return;
    
      $form['FIELDNAME'][0]['#upload_validators']['example_FUNCTIONNAME'] = array();
    
      return $form;
    }
    

    Second, implement the validator function:

    function example_FUNCTIONNAME($field) {
      // variable for error messages
      $errors = array();
    
      // do some processing on the field
      $filepath = $field->filepath;
    
      ...
    
      // in case of error, add error message
      $errors[] = t('Validation failed, because...');
    
      return $errors;
    }
    

    Put this code in a custom module, but make sure that your module is called after FileField and ImageField (adjust weight in system table).

    Update: There is another way to hook into it. You can use hook_nodeapi to react on operation “presave”. This also allows you to call a script on the content of the uploaded field.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set that that I would like to call in a
I would like to allow users to call my ruby on rails app as
I would like to call JavaScript function many time . I have tried like
I would like to call a Python script from within a Bash while loop.
I have a vector of pointers. I would like to call a function for
I am trying to write a Ruby script in one file. I would like
I have an object in Ruby called Post. I would like to convert post
I would like to run for example a synchronizing ruby script (in rails action
I have a nice piece of functional and tested Ruby code that I would
I have a Rakefile with a Rake task that I would normally call from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.