使用HTML5 / JavaScript生成并保存文件

本文翻译自:Using HTML5/JavaScript to generate and save a file

I've been fiddling with WebGL lately, and have gotten a Collada reader working. 我最近一直在摆弄WebGL,并让Collada阅读器工作。 Problem is it's pretty slow (Collada is a very verbose format), so I'm going to start converting files to a easier to use format (probably JSON). 问题是它相当慢(Collada是一种非常冗长的格式),所以我将开始将文件转换为更易于使用的格式(可能是JSON)。 I already have the code to parse the file in JavaScript, so I may as well use it as my exporter too! 我已经有了使用JavaScript解析文件的代码,因此我也可以将其用作导出器! The problem is saving. 问题正在保存。

Now, I know that I can parse the file, send the result to the server, and have the browser request the file back from the server as a download. 现在,我知道我可以解析文件,将结果发送到服务器,然后让浏览器从服务器请求文件下载作为下载。 But in reality the server has nothing to do with this particular process, so why get it involved? 但是实际上,服务器与此特定过程无关,那么为什么要参与其中呢? I already have the contents of the desired file in memory. 我已经在内存中保存了所需文件的内容。 Is there any way that I could present the user with a download using pure JavaScript? 有什么办法可以使用户使用纯JavaScript进行下载? (I doubt it, but might as well ask...) (我对此表示怀疑,但也可能会问...)

And to be clear: I am not trying to access the filesystem without the users knowledge! 需要明确的是:我不会在用户不知情的情况下访问文件系统! The user will provide a file (probably via drag and drop), the script will transform the file in memory, an

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值