我有一个小应用程序,我使用socket.io-stream将文件从服务器发送到客户端,这非常完美!
现在我想将二进制数据从客户端发送到服务器:
// [SERVER] - should receive binary data and save it as myfile.blob
ss( socket ).on( 'CreateFile', async function( stream, req ){
stream.pipe(fs.createWriteStream("./data/myfile.blob"));
});
// [CLIENT/Browser] - should send binary data to server
let binary = new Uint8Array( 32 );
let stream = ss.createStream();
ss( _socket ).emit( 'CreateFile', stream, { fileName: "foo.jpg" } );
ss.createBlobReadStream( new Blob( [ binary ] ) ).pipe( stream );
文件“ myfile.blob”已创建。 有谁知道为什么可能是错的?非常感谢你!