Move File in ExpressJS/NodeJS

前端 未结 4 1939
执笔经年
执笔经年 2021-01-04 18:50

I\'m trying to move uploaded file from /tmp to home directory using NodeJS/ExpressJS:

fs.rename(\'/tmp/xxxxx\', \'/home/user/xxxxx\         


        
4条回答
  •  粉色の甜心
    2021-01-04 19:28

    Yes, fs.rename does not move file between two different disks/partitions. This is the correct behaviour. fs.rename provides identical functionality to rename(2) in linux.

    Read the related issue posted here.

    To get what you want, you would have to do something like this:

    var source = fs.createReadStream('/path/to/source');
    var dest = fs.createWriteStream('/path/to/dest');
    
    source.pipe(dest);
    source.on('end', function() { /* copied */ });
    source.on('error', function(err) { /* error */ });
    

提交回复
热议问题