admin管理员组文章数量:1279146
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);
});
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);
});
Share
Improve this question
edited May 23, 2017 at 12:22
CommunityBot
11 silver badge
asked Aug 11, 2015 at 7:11
user1775888user1775888
3,31314 gold badges49 silver badges67 bronze badges
3
-
1
You need to give the actual filename in the
destinationFile
– thefourtheye Commented Aug 11, 2015 at 7:13 -
you mean something like this
var destinationFile = appDir+'/assets/images/UploadTemporary/'+newfilename
– user1775888 Commented Aug 11, 2015 at 7:14 - 1 Exactly. I think you are thinking that giving just the directory name will create a file with the source file name, right? – thefourtheye Commented Aug 11, 2015 at 7:15
1 Answer
Reset to default 9When you are writing a file to a specific directory, you need to give the actual destination file name as well. Unlike cp
mand, 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 ments,
var destinationFile = appDir + '/assets/images/UploadTemporary/' + newfilename;
include the file name as well.
本文标签: javascriptnodejs Error EISDIRopenStack Overflow
版权声明:本文标题:javascript - node.js Error: EISDIR, open - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741297962a2370924.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论