[英]node.js Error: EISDIR, open
I tried to uplaod file and move to new directory already exists. 我试图uplaod文件并移动到新目录已经存在。 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)
按照在Node.js中编写文件,但我收到错误:
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? 我发现使用Node.js我得到,“错误:EISDIR,读取”和Node.js错误:EISDIR,打开错误类似的错误消息,我的
UploadTemporary
文件夹已经存在我搞错了什么? 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. 与
cp
命令不同, fs
模块不会推断目标文件名。
In your case, you are trying to write to a directory, instead of a file. 在您的情况下,您尝试写入目录而不是文件。 That is why you are getting
EISDIR
error. 这就是您收到
EISDIR
错误的原因。 To fix this, as you mentioned in the comments, 要解决这个问题,正如您在评论中提到的那样
var destinationFile = appDir + '/assets/images/UploadTemporary/' + newfilename;
include the file name as well. 也包括文件名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.