Using Drupal 8. On a cloud based site, I have a program for converting images into svgs that takes, at times, a few hours of run time. I can easily run the external binary program (configured to run through java as a commandline). At the end I have the program spit out the relevant files. I need to integrate this with Drupal and am wondering the best procedures.

What do I use to grab the image and have an actual file on disk? How can I get the files back into drupal whenever this program finishes. I can easily add in commands to run after the program finishes, and can get the program to run with an exec() but how do I hook the rest of it up? A working proof of concept would be great. Even better if it could run on a spun up virtual computer on google cloud services.

1 Answer 1


Not anything near a working proof of concept, but a hint in the right direction:

You could use FileEntities for the upload of the Files, for example via a FileField on a node.

In hook_node_insert() and or hook_node_update() you can get the path to the file in the filesystem via:

$file = $node->field_source->entity;
$path = FileSystem::realpath($file->getFileUri());

You could than trigger the execution of your external program. By using hook_cron() you could regularly check for results. You could than attach the resulting file to the node like this

// Create FileEntity from a local file.
$uri  = file_unmanaged_move($path, 'public://'.$result_filename, FILE_EXISTS_RENAME);
$file = File::Create([
    'uri' => $uri,
// Load node and attach the file.
$node = Node::load($nid);
    'target_id' => $file->id(),
  • Partway through, totally got the file out of Drupal. The program itself is of my own creation so adding things like triggering commands like curl and maybe through a REST API to get the files in question seems a bit more proactive than Cron. Also, then the running server could be elsewhere (different cloud system). Then I could have a central system and run cloud instances of various other systems without bogging down the main system running the webserver.
    – Tatarize
    May 14, 2016 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.