Advertisement
shopnilSS

File Upload With CKEditor Backend

Dec 31st, 2021
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //blog image upload
  2. const blogImageUploadController = async (req, res, next) => {
  3.     try {
  4.         var TempFile = req.files.upload;
  5.         var TempPathfile = TempFile.path;
  6.  
  7.         const targetPathUrl = path.join(__dirname,"../../../public/"+TempFile.name);
  8.         if(path.extname(TempFile.originalFilename).toLowerCase() === ".png" || ".jpg"){
  9.            
  10.             fs.rename(TempPathfile, targetPathUrl, err =>{
  11.  
  12.                 res.status(200).json({
  13.                 uploaded: true,
  14.                 url: `http://localhost:3030/${TempFile.name}`
  15.                 });
  16.                 if(err) return console.log(err);
  17.             })
  18.         }
  19.         console.log(TempPathfile)
  20.  
  21.  
  22.     }catch (err) {
  23.         console.log(err)
  24.         res.json ({
  25.             message: err.message
  26.         })
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement