![](/img/trans.png)
[英]How to encoded files in base64 in nodejs after getting details from client-side using multer
[英]How to send base64 url data using json from javascript client to nodejs server using websocket?
我正在嘗試將base64網址從javascript發送到nodejs,但是我沒有找到正確的方法來做到這一點。 如果有人知道,請幫忙! 謝謝。
這是我嘗試的代碼,
Client.js
var image = document.getElementById("canvas").toDataURL("image/jpeg");
var encoded = btoa(JSON.stringify(image));
connection.send(encoded);
Server.js
connection.on('message', function(message){
console.log("Message: "+message);
if (message.type === 'utf8') { // accept only text
var post = Buffer.from(message.data).toString('base64');
console.log("post: "+post);
}
});
哪個錯誤:
Message: [object Object]
buffer.js:207
throw new ERR_INVALID_ARG_TYPE(
^
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
謝謝 !!
嘗試這個。
客戶
var base64 = document.getElementById("canvas").toDataURL("image/jpeg");
connection.send(base64);
服務器
connection.on('message', function (message) {
console.log("Message: " + message);
if (message.type === 'utf8') { // accept only text
var post = message.utf8Data;
console.log("post: " + post);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.