Reputation: 1101
I'm having a hard time figuring out how to send a file over a WebSocket using Google Protocol buffers.
My message structure for the buffer is
message FileData_m {
required uint32 block = 1; // File starting offset
required bytes data = 2; // Size of 65536 for blocks
}
The idea is to break up the file into blocks and send it over a WebSocket. Currently I'm running a Node.js server that handles interactions between host and server I just don't know how to properly send the file in a binary manner.
Any help and/or pointing me in the right direction would be very helpful!
Upvotes: 2
Views: 2937
Reputation: 1101
The solution to this was to make sure that my data was being sent using an array buffer
var dataToSend = new ArrayBuffer(65536);
dataToSend = file; // File that was uploaded from file chooser
Then when creating your protobuf message just use that array buffer as your source of data
var FileData = new FileData({
"block": 0,
"data": dataToSend
});
Upvotes: 2