Node.js & Express fs.rename random Error: EPERM, operation not allowed! How to fix it?

I have a problem with the fs.rename function! Sometimes it doesn't work and I don't know why. I am trying to download some files and rename them! So it should be a time job. in the codes below:

exports.up = function(req, res){
        var len = [].concat(req.files.fileSelect);
            for(var i = 0; i < len.length; i++) {
                var tmp_path =(len[i].path);
                if(len[i].name ==''){
                len[i].name ='empty';

                }
                    console.log(len[i]);
                    var target_path =('./public/images/' + len[i].name);
                    fs.rename(tmp_path, target_path, function(err) {
                        if (err) throw err;
                        fs.unlink(tmp_path, function() {
                            if (err) throw err;
                        });
                    });
            }   
            res.redirect('/picture');
    };

      

+3


source to share





All Articles