简体   繁体   English

“另存为”角度应用程序中HTML5本地存储中的文件

[英]“Save As” a file that is in HTML5 local storage in angular application

I have seen a number of questions that talk about getting data into HTML5 local storage and even seen a cool text editor that saves the files in local storage. 我已经看到了许多关于将数据导入HTML5本地存储的问题,甚至还看到了一个将文件保存在本地存储中的酷文本编辑器。 I have a similar application and would like to now be able to let a user take a file they have been editing in local storage and then save it on their desktop. 我有一个类似的应用程序,并希望现在能够让用户获取他们在本地存储中编辑的文件,然后将其保存在桌面上。

I can stream the file up to a service on the server and get the browser to prompt that way but I was hoping to keep it all client side. 我可以将文件流式传输到服务器上的服务并让浏览器以这种方式提示,但我希望将其保留在客户端。 The files are typically going to be text or xml based. 这些文件通常是基于文本或基于xml的。 Is there a way to setup a service in angular to take the bytes of the file in local storage then stream that and make the browser prompt the user for the save location etc. 有没有办法以角度设置服务,以获取本地存储中的文件的字节然后流式传输,并使浏览器提示用户的保存位置等。

Any help keeping it client side would be greatly appreciated. 保持客户端的任何帮助将不胜感激。

Rich 丰富

You don't need to upload the file to a server and let the user donwload it - it makes no sense. 您不需要将文件上传到服务器并让用户下载它 - 这没有任何意义。 What if the server shouldn't be allowed to access this file? 如果不允许服务器访问此文件怎么办?

Anyway, I use the FileSaver.js library in my angularJS projects and it works just fine. 无论如何,我在angularJS项目中使用FileSaver.js库 ,它工作得很好。

You can serve several files in a file archive with libraries such as JSZip . 您可以使用JSZip等库在文件存档中提供多个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM