Resending image in embed doesn't work on production, but works on dev

Hello, I have an function, that will resend any picture from a channel to another but in embed Workflow is Channel A gets a message with picture -> picture gets broken down to a base64 stream -> saved to a sequelize database as a Sequelize.TEXT data type-> Loaded using fs to create the image into local directory -> Loaded using attachmentBuilder and then used in setImage() -> Then Bot sends that embed into a channel B This all works on my computer when testing, but when deployed on production env, the images are broken and not working as it seems as seen in picture
6 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
kibubek
kibubekOP2y ago
async function saveImage(message) {

const attachment = message.attachments.first();

if (attachment) {
try {
const response = await axios.get(attachment.url, { responseType: 'arraybuffer' });
const buffer = Buffer.from(response.data, 'binary');
const base64 = buffer.toString('base64');


Image.create({
userId: message.author.id,
messageTimestamp: message.createdTimestamp.toString().slice(0, -3),
messageUrl: message.url,
messageId: message.id,
//image: `data:${attachment.contentType};base64,${base64}`
image: base64
});
} catch (error) {
console.error('Error saving image to database:', error);
}
}
}
async function saveImage(message) {

const attachment = message.attachments.first();

if (attachment) {
try {
const response = await axios.get(attachment.url, { responseType: 'arraybuffer' });
const buffer = Buffer.from(response.data, 'binary');
const base64 = buffer.toString('base64');


Image.create({
userId: message.author.id,
messageTimestamp: message.createdTimestamp.toString().slice(0, -3),
messageUrl: message.url,
messageId: message.id,
//image: `data:${attachment.contentType};base64,${base64}`
image: base64
});
} catch (error) {
console.error('Error saving image to database:', error);
}
}
}
kibubek
kibubekOP2y ago
This is what happens on production when I open the image
kibubek
kibubekOP2y ago
This is while on local machine
kibubek
kibubekOP2y ago
I need to work with those images in outside of this scope. It's also an archiver and we've ran into issues where discord cdn deletes files after a while, when the original message is deleted -> hence defeating the purpose of archiving Also it's fixed, if anyone stumbles upon a similiar issue, good luck, it's hell. In summary the issue was caused either by something weird, or these issues: - fs acts different on linux than windows - It didnt process the image correctly in the stream (Happens even now, but I made a reprocessing function as a workaround) I ended up compressing the images to 70% quality (Which I should've done at the start lol) It works okayish now, which is acceptable for me Nope, permissions were fine, it saved/deleted images as expected. File existed, and existed in time for it to get processed Thank you for providing solutions, i'll close this post since it's fixed
Want results from more Discord servers?
Add your server