如何从base64字符串在NodeJs中制作blob或File

Nar*_*yan 2 javascript node.js

我的后端有 base64 图像字符串,现在我想使用使用 File 或 Blob 的https://github.com/nkzawa/socket.io-stream#sscreateblobreadstreamblob-options,如何在 Nodejs 中制作 Blob?

Mar*_*arc 5

In Node.js you don't have Blobs but Buffers. You can create a buffer from a base64 string like this:

var str = "iAAANS....SUVORK5CYII="; // <-- use real base64 string here
var buf = Buffer.from(str, "base64");

stream.write(buf);
Run Code Online (Sandbox Code Playgroud)