You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea here is that the API will receive the b64 image, and push it to the canvas for processing, before saving the image and returning the processed image back to the user.
The codes for the API is this
import Canvas from 'canvas';
import path from 'path';
import fs from 'fs';
/* Download API config */
export const config = {
api: {
bodySizeLimit: '10mb',
bodyParser: {
sizeLimit: '10mb',
}
}
};
export default (req, res) => {
const { file, filename } = req.body;
processImage(file, b64 => {
fs.writeFile(absolutepathtofolder + filename, b64, { encoding: 'base64' }, function (err) {
if (err) return console.log(err);
let imageBuffer = fs.readFileSync(path);
res.setHeader('Content-Type', 'image/jpg');
res.send(imageBuffer);
});
});
}
const processImage = (b64, cb) => {
let img = new Canvas.Image();
img.onload = function () {
let oc = new Canvas.createCanvas(),
octx = oc.getContext('2d'),
iWidth = img.naturalWidth,
iHeight = img.naturalHeight;
/* Some process in here */
cb(processedB64);
}
img.src = b64;
}
Problem here is that, i can't seem to make the canvas work. It did call the processImage but when going to img.onload, nothing happened. This same code above works in NodeJs + ExpressJs, but not in NextJs API.
Need help here if there's anything that i missed here.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
As titled
Im using the node-canvas library here - https://github.com/Automattic/node-canvas
The idea here is that the API will receive the b64 image, and push it to the canvas for processing, before saving the image and returning the processed image back to the user.
The codes for the API is this
Problem here is that, i can't seem to make the canvas work. It did call the processImage but when going to img.onload, nothing happened. This same code above works in NodeJs + ExpressJs, but not in NextJs API.
Need help here if there's anything that i missed here.
All reactions