I'm trying to upload a file in which I need to extract file extension from filename, I'm using busboy library and it uploads a file but extension updates as [object, object], here is the code.
const BusBoy = require("busboy");
const path = require("path");
const os = require("os");
const fs = require("fs");
busboy.on("file", (fieldname, file, filename, encoding, mimetype) => {
const imageExtension = filename.toString().split(".")[filename.toString().split(".").length - 1];
const imageFileName = `${Math.round(Math.random() * 1000000000000)}.${imageExtension}`;
const filepath = path.join(os.tmpdir(), imageFileName);
file.pipe(fs.createWriteStream(filepath));
});
image path goes like example.com/o/461566744670.[object Object]?alt=media
I tried using filename.split(".") directly without toString() function, however it ends up giving error split is not function.