Sumit Sarkar
Sumit Sarkar

Reputation: 169

Not able to copy a file to a directory

I am copying a .jpg file to other directory(C:\myFaceApp\dropbox\exprtedFaces)

My source File : C:/myFaceApp/dropbox/faces/Monika1/1404039d-2be3-43bc-b20b-35c0f4a5954b/1404039d-2be3-43bc-b20b-35c0f4a5954b_00-00-04_crop.jpg

I am using following block of code to copy

targetPath=opts.exportDir; //C:\myFaceApp\dropbox\exprtedFaces

fs.createReadStream(req.query.facePath).pipe(fs.createWriteStream(targetPath));
res.write(JSON.stringify({ OK: 1 }));   
res.end();

I am getting an error like this:

Error: EISDIR: illegal operation on a directory, open 'C:\myFaceApp\dropbox\exprtedFaces'

Upvotes: 0

Views: 406

Answers (1)

Diasiare
Diasiare

Reputation: 755

Your problem is that you are attempting to write to a directory not a file. createWriteStream takes a filename as it's argument. Try this instead:

fs.createReadStream(req.query.facePath).pipe(fs.createWriteStream(path.join(targetPath ,"file.jpg")));

You should ofc give it a non hard coded name, this is just an example. Have a look at the path module for that.

Upvotes: 2

Related Questions