KruzVault
KruzVault
DIAdiscord.js - Imagine an app
Created by KruzVault on 6/2/2024 in #djs-questions
Send Images from MongoDB
I have been trying to send image from mongodb but nothing seems working
const imagePath = "path/to/the/image.jpeg";
const imageData = fs.readFileSync(imagePath, 'utf8');
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, 'utf8');
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);
I did something like this to upload the image from my local directory
{
name: "shadow.jpg",
contentType: "image/jpeg",
content: "Binary.createFromBase64("base64 string comes here")"
}
{
name: "shadow.jpg",
contentType: "image/jpeg",
content: "Binary.createFromBase64("base64 string comes here")"
}
this is what it looks in the database
const image = await getImageContent('shadow', 'shadow.jpg');
const imagedata = Buffer.from(image.content.buffer);
const attachment = new AttachmentBuilder(imagedata, { name: 'shadow.jpg' });
await interaction.reply({files: [attachment] });
const image = await getImageContent('shadow', 'shadow.jpg');
const imagedata = Buffer.from(image.content.buffer);
const attachment = new AttachmentBuilder(imagedata, { name: 'shadow.jpg' });
await interaction.reply({files: [attachment] });
this is how I tried retriving it it sends a file...but the file is not containing any image
3 replies
DIAdiscord.js - Imagine an app
Created by KruzVault on 5/31/2024 in #djs-questions
How many subcommand groups can I have per command?
How many subcommand groups am I allowed to have? only one subcommand group per command? discord.js v14.15.2 nodejs v20.12.0
2 replies