寻求将客户端生成的二进制文件保存到客户端计算机 [英] Looking to save a client-side generated binary file to client machine
问题描述
我需要将一组大量的客户端生成的数据(二进制)保存到客户端系统。我看了创建一个数据URI,但datasize是大的(应用程序生成的图像PDF文件的100多页)。除了数据URI,还有其他方法可以做到这一点吗?
I need to save a large set of client-side generated data (binary) to the client system. I looked at creating a Data URI, but the datasize is large (an app-generated image PDF files of 100+ pages). Is there some other way to do this other than a Data URI?
谢谢!
推荐答案
如果你想开始下载,这是要走的路:
If you want to start a download this is the way to go:
-
如果你有超过一个文件保存:将其打包成一个zip文件。我写了一个基于dart的zip库(可在 https://github.com/roberthartung/zip.dart)。
如果您只有一个文件(如果只有一个文件, zip或任何其他格式),您可以将其加载到blob,并让用户下载blob像这样:
If you have only one file (zip or any other format) you can load it into a blob and let the user download the blob like this:
代码
Blob blob = new Blob(...);
AnchorElement a = new AnchorElement();
a.style.display = 'none';
document.body.append(a);
String url = Url.createObjectUrlFromBlob(blob);
a.href = url;
a.download = "file.name";
a.click();
Url.revokeObjectUrl(url);
对于chrome只有不推荐使用的FileSystem API,可以用来保存持久数据,但是猜猜你想要下载。
For chrome only there is the deprecated FileSystem API, which you could use to save persistent data, but I guess you want a download.
这篇关于寻求将客户端生成的二进制文件保存到客户端计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!