Upload file then process the file

Solution i wrote my own handler.

const { parseMultipartData, sanitizeEntity } = require('strapi-utils');
const { importStudents } = require('../../../config/functions/importStudents');

module.exports = {
  async students(ctx) {
  const user = ctx.state.user;
    if (ctx.is('multipart')) {
      const { files } = parseMultipartData(ctx);

      const uploadFile = await strapi.plugins.upload.services.upload.upload({
        data: {}, //mandatory declare the data(can be empty), otherwise it will give you an undefined error.
        files: {
          path: files.students.path,
          name: files.students.name,
          type: mime.lookup(files.students.type), // mime type of the file
          size: files.students.size,
        },
      });
      try {
        console.log(uploadFile[0].url);
        await importStudents(uploadFile[0].url, user.email);
        return 'Updated successfully';
      } catch (error) {
        console.log(error);
        return 'Seems it was an issue importing it';
      }
    }
};
2 Likes