本文介绍了通过 websocket 接收文件并启动下载对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 HTML5 Web 应用程序通过 websocket 接收作为二进制数据的文件.有没有办法启动文件下载对话框(通过javascript)将接收到的数据保存到用户磁盘?
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?
谢谢!
推荐答案
您需要构建一个 dataUri 并用它打开一个新窗口.特定的 mimetypes 可以触发浏览器的自动另存为对话框.
You need to build a dataUri and open a new window with this. Specific mimetypes can trigger the browser's automatic save as dialog.
示例数据uri:"data:application/octet-stream,base64" + base64binary
这篇关于通过 websocket 接收文件并启动下载对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!