我似乎无法使 fs.createFileStream 写入目录。
var filePath = fs.createWriteStream('./path/to/store/file.png');
var rem = rquest('http://domain.com/img/img.png');
rem.on('data', function(chunk) {
filePath.write(chunk);
response.write(chunk);
});
rem.on('response', function(res){
response.writeHead(200, res.headers);
});
rem.on('end', function() {
response.end();
});
如果我将文件名传递到 CreateWritStream 中,它就可以正常工作
var filePath = fs.createWriteStream('file.png');
我做错了什么?
最佳答案
正如@thefourtheye 在评论部分所述
It will not create the directories on its own. All the directories in the path should exist and should be writable.
是正确的解决方案。
关于javascript - Node Js CreateWriteStream不会写入目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30617559/