英文:
How to convert image to base64 in node.js
问题
我需要将 fotoName
转换为 base64
,有人可以帮助我吗?
英文:
I tried to convert image that uploaded using postman, this is my code to handle image in controller
const foto = req.files.foto;
const fotoName = foto.name;
res.send(fotoName);
I need to convert fotoName
to base64
, anybody please help me?
答案1
得分: 0
尽管不建议这样做,但以下是您如何执行此操作:
var nameBase64 = Buffer.from(foto.name).toString('base64')
res.send(nameBase64);
请记住,在数据库中保存数据的时候,Base64 不是一个方便的方式。您将会遇到极长的加载时间。
英文:
Altough it isn't recommendet to do, this is how you would do it
var nameBase64 = Buffer.from(foto.name).toString('base64')
res.send(nameBase64);
Keep in mind, base64 is not a convinient way to save data in f. e. a database. You will encounter huge loading times.
答案2
得分: 0
base64
不建议在数据库中使用,因为它可能会增加加载和处理时间。然而,你可以像这样尝试使用:
// 将图像数据转换为base64
const base64Image = data.toString('base64');
res.send(base64Image);
英文:
base64
is not recommended in database because it may actually increase the loading and processing times. However you can you can try it like this:
// Convert the image data to base64
const base64Image = data.toString('base64');
res.send(base64Image);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论