簡體   English   中英

如何將包含圖像的 Base64 代碼的字符串轉換為字節?

[英]how to convert string that contains Base64 code of a image to 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將其另存為文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM