How can get file in beforeCreate and attached to nodemailer?

[details="System Information"]
- **Strapi Version**: 4.4.1
- **Operating System**: windows
- **Database**: pg
- **Node Version**: 16.13.2
- **NPM Version**: 
- **Yarn Version**: 1.22.15

I’m using Strapi v4 as my backend and I want to send an email using Nodemailer in the beforeCreate or afterCreate lifecycle hook of a content type. I need to access a file uploaded during the creation of the content and attach it to the email. Here’s an example of my code:

beforeCreate: async (event) => {
  const ctx = strapi.requestContext.get();
  const { full_name, email } = JSON.parse(;
  const file = ctx.request.files;
  const trackingCode = await strapi.config.helperFunction.generateRandomItn(event);
  try {
    const emailOptions = {
      to: email,
      subject: subject,
      html: content,
      attachments: [
          path: file.path,
    await strapi.plugins['email'];
    strapi.log.debug(`Email sent`);
  } catch (err) {
    strapi.log.error(`Error sending email`, err);
    throw new ApplicationError(`Error sending email: ${err}`);

However, I’m unsure how to properly access the file within the lifecycle hook and attach it to the email. I would appreciate any guidance or code examples on how to achieve this.

Thank you!