小程序二维码接口B返回代码nodejs怎么保存图片?

发布于 7 年前作者 yongyu3610 次浏览最后编辑 7 年前来自 ask

请问下node.js怎么把小程序二维码接口B返回的二维码二进制流保存成图片文件?直接使用fs.writefile方法保存的图片无法打开

6 回复
zhouchao
zhouchao1 楼6 年前

请求回来的数据自动编码了,设置encoding : null就行,详见:https://segmentfault.com/a/1190000002787763

还写了一个博客,https://blog.csdn.net/uikoo9/article/details/86088028

agu
agu2 楼6 年前

request({

                            url: ‘https://api.weixin.qq.com/wxa/getwxacodeunlimit?access\_token=’ + token,

                            method: ‘POST’,

                            headers: {

                                ‘content-type’: ‘application/json’

                            },

                            body: JSON.stringify({

                                scene: scene

                            })

                        }, function() {

                            res.send(imgUrl)

                        }).pipe(fs.createWriteStream(file_address))

用nodejs的request

包的.pipe(fs.createWriteStream(‘xxxx.jpg’))

jing84
jing843 楼6 年前

大佬,搞定没?怎样用node.js将二进制流转化为图片

zhangping
zhangping4 楼6 年前

谢谢了

fhou
fhou5 楼6 年前

大佬能不能给我完整的demo

    body: JSON.stringify({

                                scene: scene

                            })

                        }, function() {

                            res.send(imgUrl)

                        }).pipe(fs.createWriteStream(file_address))

这块小弟我看不懂啊

jietian
jietian6 楼5 年前

只有JAVA和PHP的例子,node.js的没有人有么