Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js Error: EISDIR, open

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);
});
like image 247
user1775888 Avatar asked Mar 16 '23 03:03

user1775888


1 Answers

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.

like image 70
thefourtheye Avatar answered Mar 23 '23 17:03

thefourtheye