小程序二维码接口B返回代码nodejs怎么保存图片?
发布于 6 年前 作者 yongyu 3415 次浏览 来自 问答

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

6 回复

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

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

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’))

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

大佬能不能给我完整的demo

    body: JSON.stringify({

                                scene: scene

                            })

                        }, function() {

                            res.send(imgUrl)

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

这块小弟我看不懂啊

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

回到顶部