Node.js fs rename ENOENT

I am trying to write a handler for uploading files to node.js using express framework. Below is its original skeleton.

exports.handleUpload = function(req,res){

var temp_path = req.files.doc.path,
    target_path = './uploads/' + req.files.doc.name ;


fs.rename(temp_path, target_path, function(err){

    if(err){
        console.log(err);
    }

    fs.unlink(temp_path, function(){
        if(err){
            console.log(err)

        }

    })

    //Do stuff  

})

}

However, I sometimes get an error when executing the renmae function (not always), especially when downloading large files.

This is what the console caches from the error code

{ [Error: ENOENT, rename '/tmp/16368-19661hu.pptx'] errno: 34, code: 'ENOENT', path: '/tmp/16368-19661hu.pptx' }

From: https://github.com/joyent/node/blob/master/deps/uv/include/uv.h

XX(ENOENT, "no such file or directory") 

The uploads / directory exists and permissions are not a problem. If this were the case, it would fail every time, but it is not.

+4
source share
1 answer

/tmp. , /tmp, , "" . fs.exists .

-1

All Articles