最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - receive file via websocket and initiate download dialog - Stack Overflow

programmeradmin3浏览0评论

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!

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!

Share Improve this question asked Mar 26, 2012 at 11:34 Herbert StiftlerHerbert Stiftler 1311 gold badge1 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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

Not yet, no. The new File API currently only covers reading. Update: See Peter's answer if you only need to do this on cutting-edge (and to date, non-IE) browsers, where you can do it with the data: URI scheme.

The usual way to do this would be to receive the file via HTTP into a hidden iframe using Content-Disposition: attachment to trigger the file download dialog, rather than receiving it via a web socket.

发布评论

评论列表(0)

  1. 暂无评论