How do I programatically get access to the file uploaded to a webform after a submission? I am using business rules custom action to access the submission data on entity insert.
I am able to get the file id and ultimately the realpath.
the real path is sites/default/files/private/webform/[webform_name]/_sid_/[file_name].
When I try to attach this file it is as if it were not there and ultimately gets moved into sites/default/files/private/webform/[webform_name]/[webform_submission_id]/[file_name].
I have tried to use the above path but it as if the file had not been written yet.
After the action has been completed I can attach the file with no problem.


The issue I am having is how can I get this illusive file and attach it to an email pragmatically.

here is the snipet of code that will generate the "/_sid_/" path

$file_id = $event['entity']-&gt;getData()[$file_field];
$file = \Drupal\file\Entity\File::load($file_id);
$realpath = \Drupal::service('file_system')-&gt;realpath($file-&gt;getFileUri());


Thank you for your responses and help on this.
Well, as first posts go, it ended up as a "stupid" mistake on my end. The webfrom module is well documented and the solution was very straight forward. (In short I was pushing an array into the ->AddAtachment method in PHPMailer.) For reference to anyone else here is my working code:

[module_name]\src\Plugin\BusinessRulesAction\SMTPAuthEmail.php

namespace Drupal\[module_name]\Plugin\BusinessRulesAction;
use Drupal\[module_name]\Controller\[module_name]Controller;
use Drupal\business_rules\ActionInterface;
use Drupal\business_rules\Events\BusinessRulesEvent;
use Drupal\business_rules\ItemInterface;
use Drupal\business_rules\Plugin\BusinessRulesActionPlugin;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render;
use Drupal\Core\File\FileSystem;
use Drupal\file\Entity\File;


class SMTPAuthEmail extends BusinessRulesActionPlugin {
    public function getSettingsForm(array &amp;$form, FormStateInterface $form_state, ItemInterface $item) {
        //var_dump($item);
        $settings['email_settings'] = [
            '#type'          =&gt; 'fieldset',
            '#title'         =&gt; t('Email Settings'),
        ];
//this is just to show that I have a form for business rules that is being referenced later below.


    public function execute(ActionInterface $action, BusinessRulesEvent $event) {
    $send_email = new [module_name]Controller;
    $message = $action-&gt;getSettings();
    $css = file_get_contents(drupal_get_path('module', '[module_name]') . '/css/email.css');
    $entity_type = $event['entity']-&gt;getEntityTypeID();
    $node_storage = \Drupal::entityTypeManager()-&gt;getStorage($entity_type);
    $view_builder = \Drupal::entityTypeManager()-&gt;getViewBuilder($entity_type);
    $node = $node_storage-&gt;load($event['entity']-&gt;id());
    $build = $view_builder-&gt;view($node, 'table');
    $file_fields = $event['entity']-&gt;getWebform()-&gt;getElementsManagedFiles();
     if($file_fields){
        foreach ($file_fields as $file_field) {
            if (!empty($event['entity']-&gt;getData()[$file_field])) {
                $file_id = $event['entity']-&gt;getData()[$file_field];
                $file = \Drupal\file\Entity\File::load($file_id);
                $realpath = \Drupal::service('file_system')-&gt;realpath($file-&gt;getFileUri());
                $message['attachment'][] = $realpath;
            }
        }
    }
    $message['body'] = '&lt;style&gt;' . $css . '&lt;/style&gt;' . render($build);
    $send_email-&gt;smtp_email($message);

}


[module_name]\src\Controller[ModuleName]Controller.php

class [ModuleName]Controller extends ControllerBase {

    public function smtp_email($data) {

        $mail = new PHPMailer();
        $mail-&gt;IsHTML(true);
        $mail-&gt;IsSMTP(); // enable SMTP
        $mail-&gt;SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
        $mail-&gt;SMTPAuth = true; // authentication enabled
        if($data['tls']){
            $mail-&gt;SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
        }
        $mail-&gt;Host = $data['host'];
        $mail-&gt;Port = $data['port']; // or 587

        $mail-&gt;Username = $data['username'];
        $mail-&gt;Password = $data['password'];
        $mail-&gt;SetFrom($data['from']);
        $mail-&gt;Subject = $data['subject'];
        $mail-&gt;Body = $data['body'];
        if(isset($data['attachment'])) {
            foreach ($data['attachment'] as $attachment) {
                $mail-&gt;AddAttachment($attachment);
            }
        }
        foreach(explode(";",$data['to']) as $recipient) {
            $mail-&gt;AddAddress($recipient);
        }
        if(!$mail-&gt;Send()) {
            $message = "Mailer Error: " . $mail-&gt;ErrorInfo;
            $message_type = 'error';
        } else {
            $message =  "Message has been sent";
            $message_type = 'notice';
        }
        \Drupal::messenger()-&gt;addMessage(t($message), $message_type);
    }

}


I hope this helps someone!