如何将包含图像的 Base64 代码的字符串转换为 Byte



我正在尝试将图像保存在猫鼬中,我的客户端将该图像转换为 Base64 字符串并将其发送到服务器,我想将该字符串保存到字节因为字符串大小大于图像,我想提高性能

这是我的英雄收藏

var mongoose = require('mongoose');
var Heroes = mongoose.model('Heroes',{
    Name:{
        type: String,
        required: true,
        trim: true 
    },
    Heroes_Image:{
        type: String,
        required: true
    }
});
module.exports = {Heroes};

这是我的服务器端:

var {mongoose} = require('./db/mongoose');
var {Heroes} = require('./models/Heroes');
var net = require('net');
var db = mongoose.connection;
var clients = [];
net.createServer(function (socket) {
    // Identify this client
    socket.name = socket.remotePort 
    // Put this new client in the list
    clients.push(socket);
    console.log(socket.name + " joined the chat");
    socket.on('data', function (data) {
        var j = JSON.parse(data);
        db.collection('Heroes').insertOne({
            Name: j.Name,
            Heroes_Image: j.Heroes_Image
        });// here save Base64 string of client image and it waste memory
    })
});

可以使用 Blob 将其另存为文件。

最新更新