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
javascript node.js express


source to share


No one has answered this question yet

Check out similar questions:

2201
How do you decide when to use Node.js?
1517
How do I debug Node.js applications?
1388
What is the purpose of Node.js module.exports and how do you use it?
1251
How do I access matched groups in a JavaScript regex?
1177
How to completely uninstall Node.js and reinstall from the beginning (Mac OS X)
1113
How to randomize (shuffle) a JavaScript array?
868
In Node.js, how do I include features from other files?
543
How do I resolve the "Cannot find a module" error using Node.js?
2
Express request not working
1
file upload using multer doesn't work completely (nodejs)



All Articles
Loading...
X
Show
Funny
Dev
Pics