Create image from ArrayBuffer in Nodejs

橙三吉。 提交于 2019-12-04 11:48:45

Have you tried first converting it into a node.js. Buffer? (this is the native node.js Buffer interface, whereas ArrayBuffer is the interface for the browser and not completely supported for node.js write operations).

Something along the line of this should help:

all= fs.createWriteStream("out."+imgtype);

for(i=0; i<end; i++){
    var buffer = new Buffer( new Uint8Array(picarray[i]) );
    all.write(buffer);
}
all.end();

after spending some time i got this, it worked for me perfectly.

as mentioned by @Nick you will have to convert buffer array you recieved from browser in to nodejs Buffer.

var readWriteFile = function (req) {
    var fs = require('fs');
        var data =  new Buffer(req);
        fs.writeFile('fileName.png', data, 'binary', function (err) {
            if (err) {
                console.log("There was an error writing the image")
            }
            else {
                console.log("The sheel file was written")
            }
        });
    });
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!