Turn from: http://marshal.easymorse.com/archives/4935
The picture is manipulated in the browser's JavaScript and can only be Base64 encoded text. For example, storing pictures from HTML5 canvas can only generate Base64 encoded text through the Todataurl () method.
The generated input looks like this:
data:image/png;base64,ivborw0kggoaaaa......ggg==
Among them, the Png;base64, the latter part, is the picture data base64 encoding representation.
We can send the data to the server side via backbone sync, see: Backbone and express integration.
Then, you need to use Express to convert the data to binary data and save it to a file with the following code:
App.post ('/items ', function (req, res) {
Console.log (Req.body.title);
var base64data=req.body.imgdata.replace (/^data:image\/png;base64,/, "");
var binarydata=new Buffer (base64data, ' base64′ '). toString (' binary ');
Require (' FS '). WriteFile (' Out.png ', binarydata, ' binary ', function (err) {
if (err) {
Console.log (ERR);
}
});
Res.send (' saved. ');
});