How do I convert readable image stream into base64

2019-07-28 18:55发布

I want to convert an image in azure to base64. How can I achieve this using azure-storage package?

this.blobService.getBlobProperties(
                'container',
                path,
                (err, properties, status)=> {
                    if (err) {
                         res.send(502, "Error fetching file: %s", err.message);
                    } else if (!status.isSuccessful) {
                        res.send(502, "The file %s does not exist", fileName)
                    } else {
                         res.header('Content-Type', properties['contentType']);
                         this.blobService.createReadStream('container', path,(error,response)=>{
                         }).pipe(res);
                    }
                });

The response I get is like this, I want to convert this(octet/stream) to base64.

enter image description here

2条回答
Ridiculous、
2楼-- · 2019-07-28 19:14

There is no built-in Node.js method to do that. Some 3rd npm packages you can use, for example, https://www.npmjs.com/package/base64-stream

查看更多
女痞
3楼-- · 2019-07-28 19:38

Try

var dataUrl="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAA.."; var buffer = new Buffer(dataUrl.split(",")[1], 'base64');

查看更多
登录 后发表回答