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);
});
});
};
How to kill a query running by pd.read_sql and connected by sqlalchemy (or mysql.connector)
Radio and checkbox cannot be checked when inside BootStrap Modal
please, help me understand how to switch my Telegram bot from polling to webhookI have a VPS server where my bot is deployed
Want to improve this question? Add details and clarify the problem by editing this post
I m using a web view wherein my pages are renderedI want to apply FLAG_SECURE on the web view
I copied one dataframe to another using the below code