Looking at the code from @pmogollon, which I think has a typo, along with your original request to write to the db with one call, can you try this:
export const insertMeme = new ValidatedMethod({
name: 'memes.insert',
validate: memeSchema.validator({ clean: true, filter: true }),
async run(document) {
if (Meteor.isServer) {
const base64string = document.image.replace('data:image/png;base64,', '');
const sharp = require('sharp');
const image = await sharp(Buffer.from(base64string, 'base64'))
.png({ compressionLevel: 9, adaptiveFiltering: true, force: true })
.resize({ width: 500 })
.toBuffer();
document.image = 'data:image/png;base64,' + image.toString('base64');
const _id = Memes.insert(document);
}
return _id;
},
});
Incidentally, using document is a bit risky in the browser, as it’s reserved for the HTML document. Better to use doc, maybe.