KruzVault
KruzVault
DIAdiscord.js - Imagine an app
Created by KruzVault on 6/2/2024 in #djs-questions
Send Images from MongoDB
const imagePath = "path/to/the/image.jpeg";
const imageData = fs.readFileSync(imagePath);
const imageBuffer = Buffer.from(imageData);
const imageBinary = new mongodb.Binary(imageBuffer);
const imageMimeType = mime.lookup(imagePath);

image = {
name: i,
contentType: imageMimeType,
content: imageBinary
}
imagesData.push(image);
const imagePath = "path/to/the/image.jpeg";
const imageData = fs.readFileSync(imagePath);
const imageBuffer = Buffer.from(imageData);
const imageBinary = new mongodb.Binary(imageBuffer);
const imageMimeType = mime.lookup(imagePath);

image = {
name: i,
contentType: imageMimeType,
content: imageBinary
}
imagesData.push(image);
it should have been like this no need to read it with utf8 removing that fixed my code
3 replies