How do I convert readable image stream into base64 without saving locally

自作多情 提交于 2019-12-24 08:49:19

问题


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.


回答1:


Try

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




回答2:


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



来源:https://stackoverflow.com/questions/50796593/how-do-i-convert-readable-image-stream-into-base64-without-saving-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!