[英]upload and save image from google-drive api node.js
我是节点的新手。 我一直在努力寻找如何路由我从谷歌驱动器 api 获取的传入图像。我尝试下载它,但需要很长时间。 我希望能够在收到后立即将其发送给客户。 这可能很简单,但我只想将其保存到 png 文件中。 . ant 帮助将不胜感激。
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"));
你可以将 pipe 传入的数据直接写入一个文件:
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"));
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.