const mime = require('mime-types'); //used to detect file's mime type${rootDir}/public/uploads/${fileName}`
const fs = require('fs');
const rootDir = process.cwd();
const fileName = 'test.csv';
const filePath =
const stats = fs.statSync(filePath);
//uploading it directly to upload services.
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: filePath, 
        name: fileName,
        type: mime.lookup(filePath), // mime type of the file
        size: stats.size,
    },
});`
https://forum.strapi.io/t/strapi-upload-plugin-how-to-place-a-file-generated-from-strapi-backend-js-code/3323
    
Top comments (0)