Flask-socketio: Attach data file during emiting

Created on 21 Oct 2016  路  2Comments  路  Source: miguelgrinberg/Flask-SocketIO

Hello, I wonder if it is somehow possible to emit some file\data from the JS client to the Flask-SocketIO server?

I need to send audio data recorded from the browser along with some other regular text\json data.

It is possible with socketio? How should I approach it? Or should I rely on ajax and post stuff rather?
Thanks!

question

Most helpful comment

You can send binary data, that's supported. Even more, you can combine binary and JSON data in one message. So for example, you could send something like this:

socket.emit('recording', {'audio_data': binary_data, 'metadata': {'channels': 2, 'rate': 44100}});

For the server, I recommend you use Python 3, as that will make it easier to work with and differentiating between binary and text data.

All 2 comments

You can send binary data, that's supported. Even more, you can combine binary and JSON data in one message. So for example, you could send something like this:

socket.emit('recording', {'audio_data': binary_data, 'metadata': {'channels': 2, 'rate': 44100}});

For the server, I recommend you use Python 3, as that will make it easier to work with and differentiating between binary and text data.

But, just worth mentioning, it looks like there's a limit to how much data you can send with one emit, so large files should be split into multiple chunks. I'm not entirely sure about this, though

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chaitanyavolkaji picture chaitanyavolkaji  路  3Comments

ypperlig picture ypperlig  路  5Comments

AlaaKho picture AlaaKho  路  3Comments

nh916 picture nh916  路  3Comments

thehelpfulbees picture thehelpfulbees  路  4Comments