Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

receive file via websocket and initiate download dialog

my HTML5 web application receives a file as binary data via a websocket. Is there any way to initiate a file download dialog (via javascript) to save the received data to the users disk?

Thank you!

like image 344
Herbert Stiftler Avatar asked Mar 26 '12 11:03

Herbert Stiftler


People also ask

How do I receive WebSocket data?

First, you need to copy your web browser's header to here and use json. dumps to convert it into the string format. After that, create the connection to the server by using create_connection . Then, perform the handshake by sending the message, and you will be able to see the data on your side.

Can we send file through WebSocket?

You can send raw binary data through the WebSocket. It's quite easy to manage. One option is to prepend a "magic byte" (an identifier that marks the message as non-JSON). For example, prepend binary messages with the B character.

When using WebSocket send () How do you know?

The only way to know the client received the webSocket message for sure is to have the client send your own custom message back to the server to indicate you received it and for you to wait for that message on the server.

Can a WebSocket server send message to client?

The Message event takes place usually when the server sends some data. Messages sent by the server to the client can include plain text messages, binary data, or images. Whenever data is sent, the onmessage function is fired. This event acts as a client's ear to the server.


1 Answers

You need to build a dataUri and open a new window with this. Specific mimetypes can trigger the browser's automatic save as dialog.

Example data uri: "data:application/octet-stream,base64" + base64binary

like image 144
Peter Aron Zentai Avatar answered Dec 06 '22 20:12

Peter Aron Zentai