Strapi v4 Upload files lifecycles beforeCreate not working

I’m trying to port this plugin https://github.com/darron1217/strapi-plugin-video-thumbnail which generates thumbnail automatically when you upload a video to v4

i’ve followed the migration blog information https://strapi.io/blog/v4-plugin-migration-guide and after handling few errors the server seems to run fine…but the plugin is not working

"use strict";

// module.exports = ({ strapi }) => {
//   // bootstrap phase
// };

const ffmpeg = require("fluent-ffmpeg");

module.exports = ({ strapi }) => {
  // console.log(strapi.plugins.upload.contentTypes.file.lifecycles);
  // console.log(strapi.plugins["strapi-plugin-ffmpeg-thumbnail"].services['videoThumbnail']);
  // inject lifecycle hook
  // TODO : Find better way to trigger thumbnail generation
  const { beforeCreate, ...lifecycles } =
    strapi.plugins.upload.contentTypes.file.lifecycles || {};
  const { generateThumbnail } =
    strapi.plugins["strapi-plugin-ffmpeg-thumbnail"].services["videoThumbnail"];
  console.log("doing the thing 0");

  strapi.plugins.upload.contentTypes.file.lifecycles = {
    ...lifecycles,
    beforeCreate(data) {
      console.log("doing the thing");

      // run original method (if exists)
      if (beforeCreate) {
        beforeCreate(data);
      }

      // Run if file type is video
      if (data.mime.startsWith("video")) {
        generateThumbnail(data);
      }
    },
    afterCreate(data){
      console.log('done the thing')
    }
  };
  console.log(strapi.plugins.upload.contentTypes.file.lifecycles);
};

here’s the new bootstrap.js in server folder of the plugin

i think i’m doing something wrong with strapi.plugins.upload.contentTypes.file.lifecycles

even the console.logs are not working

how do i do something when a content is uploaded on strapi v4?

1 Like

Hi @sergiorow,

I’m facing the same issue.

Did you find a way to achieve migration ? or to access to beforeCreate hook ?