Hi there.
I’m in a bit of a pickle 
I’m trying to process a json file of data.
I can do this on startup on bootstrap.js
so this is working as intended.
What I’m struggling with is to use a POST request to uploads
to then fire the function and process the data.
Where can do this ? Would it be to create the upload extension and create a custom route ?
Would be great to hear any others that could shed any light on this 
Strapi: 3.6.7
1 Like
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