need help in compassing an image in the backend

55
February 22, 2021, at 00:30 AM

hello i am all new to node i build the backend using the express framework , i try to compress image on the fly , i use the formidable to receive the files, and for the compress i use compress-images,for storage i use mongodb , this is what i try to do, to compress in the same folder and replacing the original upload to the new compressed , cant figure how to do it tried to do like in the example code does not work , still pass the original file, some one help please

exports.createPost = (req, res) =>{
let form = new formidable.IncomingForm();
form.keepExtensions = true;
form.maxFieldsSize= 2 * 1024 * 1024;
form.parse(req, (err, fields, files)=>{
    if(err){
        return res.status(400).json({error:'image could not be uploaded'});
    }
    let post = new Post(fields);
    const {emotion , color} = post;
    post = _.extend(post,ECBrige2(emotion,color));
    post.postedBy = req.profile;
    req.profile.hashed_password = undefined;
    req.profile.salt = undefined;
    if(files.photo){
        compress_images(files.photo.path,files.photo.path, {compress_force: true, statistic: false, autoupdate: true}, false,
                                            {jpg: {engine: 'jpegRecompress', command: ['--quality', 'high', '--min', '60','-m', 'smallfry']}},
                                            {png: {engine: 'pngquant', command: ['--quality=20-50', '--ext=-min.png', '--force']}},
                                            {svg: {engine: 'svgo', command: '--multipass'}},
                                            {gif: {engine: 'gifsicle', command: ['--colors', '64', '--use-col=web']}}, function(err, completed, statistic){
    if(err === null){
        fs.unlink(statistic.input, (err) => {
            if (err) throw err;
            console.log('successfully compressed and deleted '+statistic.input);
        });
        console.log('completed');
    }
});
    post.photo.data = fs.readFileSync(files.photo.path);
    post.photo.contentType = files.photo.type;    
    }
    
    post.save((err,result)=>{
        if(err){
            return res.status(400).json({error:err});
        }
        res.json(result);
    });
});

};

READ ALSO
NodeJs Telegram bot on VPS, need help switching to webhook

NodeJs Telegram bot on VPS, need help switching to webhook

please, help me understand how to switch my Telegram bot from polling to webhookI have a VPS server where my bot is deployed

27
I have problem with IE11 in Grid. I uploaded my code. It work fine in chrome and firefox [closed]

I have problem with IE11 in Grid. I uploaded my code. It work fine in chrome and firefox [closed]

Want to improve this question? Add details and clarify the problem by editing this post

29
Does the usage of FLAG_SECURE with respect to activity's window blocks the user triggered foreground screenshots too?

Does the usage of FLAG_SECURE with respect to activity's window blocks the user triggered foreground screenshots too?

I m using a web view wherein my pages are renderedI want to apply FLAG_SECURE on the web view

63
Copy half the rows in a pandas dataframe to another dataframe

Copy half the rows in a pandas dataframe to another dataframe

I copied one dataframe to another using the below code

57