Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS fs.rename doesn't work

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 reported error is: EXDEV, cross-device link not permitted.

like image 810
Thomaschaaf Avatar asked Aug 30 '12 11:08

Thomaschaaf


1 Answers

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);
});
like image 113
Bruce Yo Avatar answered Sep 30 '22 20:09

Bruce Yo