I tried to uplaod file and move to new directory already exists.
follow Writing files in Node.js but I got the error:
Error: EISDIR, open '/Users/name/Sites/project/app/assets/images/UploadTemporary/'
at Error (native)
and I found Using Node.js I get, "Error: EISDIR, read" and Node.js Error: EISDIR, open Error similar error message, my UploadTemporary
folder already exists do I mess something wrong?
I don't get it, if its not a directory what else can be?
var multipart = require('connect-multiparty');
var fs = require('fs');
var path = require('path');
var appDir = path.dirname(require.main.filename);
...
var sourceFile = req.files.file[0].path;
var destinationFile = appDir + '/assets/images/UploadTemporary/';
var source = fs.createReadStream(sourceFile);
var destination = fs.createWriteStream(destinationFile);
source.pipe(destination);
source.on('end', function () {
fs.unlinkSync(sourceFile);
});
When you are writing a file to a specific directory, you need to give the actual destination file name as well. Unlike cp
command, the destination filename will not be inferred by fs
module.
In your case, you are trying to write to a directory, instead of a file. That is why you are getting EISDIR
error. To fix this, as you mentioned in the comments,
var destinationFile = appDir + '/assets/images/UploadTemporary/' + newfilename;
include the file name as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With