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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.