gpt4 book ai didi

javascript - Node Js CreateWriteStream不会写入目录

转载 作者:太空宇宙 更新时间:2023-11-04 02:25:43 27 4
gpt4 key购买 nike

我似乎无法使 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com