我是node的新手。我一直在挖掘,试图找出如何路由我从谷歌驱动器api获得的传入图像。我试着下载了,但花了很长时间。我希望我一收到就能把它发送给客户。这可能很简单,但我想做的就是将它保存到一个png文件中。。ant help将非常感谢。
app.get("/img", function(req,res){
https.get(url,function(resp){
console.log(resp.statusCode);
console.log(resp.headers['content-type']);
resp.on("data", function(chunk){
// I am getting the image raw data
.pipe(fs.createWriteStream("public/images/test.png")); 发布于 2020-04-15 07:54:35
您可以通过管道将传入的数据直接传输到文件:
resp.pipe(fs.createWriteStream("public/images/test.png"))你的代码将变成:
app.get("/img", function(req,res){
https.get(url,function(resp){
console.log(resp.statusCode);
console.log(resp.headers['content-type']);
resp.pipe(fs.createWriteStream("public/images/test.png"));
});
});https://stackoverflow.com/questions/61217061
复制相似问题