Node.JS fs.rename doesn't work

前端 未结 2 1465
长发绾君心
长发绾君心 2021-01-05 14:40

Renaming a file on Debian Wheezy does not work using fs.rename or fs.renameSync.

This only happens in files moved from /tmp/ to another location.

The reporte

2条回答
  •  借酒劲吻你
    2021-01-05 15:02

    This is another solution that works for me:

    var fs = require("fs"),
    util = require('util');
    ...
    //fs.renameSync(files.upload.path, "/tmp/test.png");
    
    var readStream = fs.createReadStream(files.upload.path)
    var writeStream = fs.createWriteStream("/tmp/test.png");
    
    util.pump(readStream, writeStream, function() {
        fs.unlinkSync(files.upload.path);
    });
    

提交回复
热议问题