[英]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.