首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从google-drive api node.js上传和保存图像

从google-drive api node.js上传和保存图像
EN

Stack Overflow用户
提问于 2020-04-15 04:53:14
回答 1查看 416关注 0票数 0

我是node的新手。我一直在挖掘,试图找出如何路由我从谷歌驱动器api获得的传入图像。我试着下载了,但花了很长时间。我希望我一收到就能把它发送给客户。这可能很简单,但我想做的就是将它保存到一个png文件中。。ant help将非常感谢。

代码语言:javascript
复制
 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")); 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-15 07:54:35

您可以通过管道将传入的数据直接传输到文件:

代码语言:javascript
复制
resp.pipe(fs.createWriteStream("public/images/test.png"))

你的代码将变成:

代码语言:javascript
复制
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"));
    });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61217061

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档