exports.editcover = async (ctx) => { const { userId, imgfile } = ctx.request.body var base64Data = imgfile.replace(/^data:image\/\w+;base64,/, ""); var dataBuffer = new Buffer(base64Data, 'base64'); let name = new Date().getTime().toString() + OrderHelper.generateRondom(10).toString(); let url = './upload/'+name+'.png' fs.writeFile(url, dataBuffer, function(err) { if(err){ console.log('保存失败'); }else{ console.log('保存成功'); console.log(url);//现在到这就结束了,我可以看到在我的upload文件下生成了我刚刚上传的图片 } }); }
相关分类