2015-04-23 134 views

回答

0

HTML5本地存储不适用于文件。

看一看Mozilla的文档在这里:https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage

相反,它是键/值对。

// Save data to the current local store 
localStorage.setItem("username", "John"); 

// Access some stored data 
alert("username = " + localStorage.getItem("username")); 

要开始下载,你可能想看看像Download File Using Javascript/jQuery

+0

但是: https://hacks.mozilla.org/2012/02/saving-images-and-files -in-localstorage/ 它说你实际上可以将任何文件保存为blob。 – Mikhail

+0

你为什么要这么做?只是要清楚,这些文件不能被用户访问 - 它们被浏览器存储在数据库文件中。 – jcuenod

0

Localstorage一个问题,你认为是不是一个数据库,甚至文件系统,它只是存储微小位一些纯JSON文件的数据在key: value对。

如果您在使用JSON之前很容易理解它背后的想法。

下面是Local-storage设置和获取价值的例子:你如何看待这个链接

locastorage.setItem('KEY',JSON.stringify('VALUE')); 
// KEY is kind of like the variable name and the VALUE is the actual Data 

JSON.prase(locastorage.getItem('KEY')); 
// You use the KEY to access the value 

// Using JSON methods stringify and prase just to be on the safer side.