Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 13, 2022 10:59 am GMT

How to place a file generated from strapi backend js code

const mime = require('mime-types'); //used to detect file's mime type
const fs = require('fs');
const rootDir = process.cwd();
const fileName = 'test.csv';
const filePath =
${rootDir}/public/uploads/${fileName}`
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


Original Link: https://dev.to/dingzhanjun/how-to-place-a-file-generated-from-strapi-backend-js-code-444k

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To