但是图片可以是svg的话
function saveAs(Url,filename){
var blob=new Blob([''], {type:'application/octet-stream'})
var url = webkitURL.createObjectURL(blob)
var a = document.createElementNS(xhtml,'a')
a.href = Url
a.download = filename
var e = document.createEvent('MouseEvents')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
webkitURL.revokeObjectURL(url)
2. saveAs(data,"new.svg")
下面一小段代码给大家分享Nodejs把接收图片base64格式保存为文件存储到服务器上的方法,具体代码如下所示:app.post('/upload', function(req, res){
//接收前台POST过来的base64
var imgData = req.body.imgData
//过滤data:URL
var base64Data = imgData.replace(/^data:image\/\w+base64,/, "")
var dataBuffer = new Buffer(base64Data, 'base64')
fs.writeFile("image.png", dataBuffer, function(err) {
if(err){
res.send(err)
}else{
res.send("保存成功!")
}
})
})