How can I use HTML5 local storage to save a little exe file and then download it by clicking the button?
Localstorage as you think is not a DataBase or even the File System, it's just some plain JSON files that store tiny bits of data in key: value pairs.
If you have worked with JSON before this will be very easy to grasp the Idea behind it.
Below is an example of setting and retrieving values from Local-storage:
locastorage.setItem('KEY',JSON.stringify('VALUE'));
// KEY is kind of like the variable name and the VALUE is the actual Data
JSON.parse(locastorage.getItem('KEY'));
// You use the KEY to access the value
// Using JSON methods stringify and parse just to be on the safer side.
HTML5 Localstorage is not for files.
Have a look at Mozilla's documentation here: https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage
Instead it's for key/value pairs.
// Save data to the current local store
localStorage.setItem("username", "John");
// Access some stored data
alert( "username = " + localStorage.getItem("username"));
To start a download, you may want to look at a question like Download File Using Javascript/jQuery
Related
I wan't to learn how connect some json file with after effects for rendering dynamic videos.
Eg i have a form in some webpage:
this form included one input which people are using there their name.
And then i create some json file like that array of objects with this form.
data = [
{
name: 'John'
},
{
name: 'Mike'
}
]
and i wan't to create with these json objects for each name some video about few second there will be shown just name from json and render some mp4 video.
How to do that?
which steps following?
if it will be web form i think i'll need to connect json file dynamically too right?
so after effects will read this json file from some url ?
There are many ways to go about doing this, but a single answer on Stack Overflow probably won't give you everything you need.
Network communication can be done using the CEP framework provided by Adobe which can then execute ExtendScript code which actually does the manipulation of the layers inside the AEP project file. You can use node modules to perform the network communication, and then write ExtendScript code to pass in the JSON data to that.
While not free, you might want to explore Dataclay's Templater extension to help you accomplish what you want. It not only does what you are asking out of the box, but it has some rules-based AI to reconfigure layers both temporally and spatially. You can point Templater to a URL that response with an array of JSON objects and have it process that data. In addition to this, it has event hooks which allow you to execute any script within the Shell or with the ExtendScript engine during its versioning process.
Hope this helps!
When we use core-localstorage
<core-localstorage name="my-app-storage" value="{{value}}"></core-localstorage>
where it actually store the data? In some file on the HDD? What is the path?
LocalStorage is one of some ways you can store data in the client end in the Hard-drive, different browsers use different locations to save this file.
LocalStraoge makes use of JSON to store information worth up to 10MB(Might differ from browsers).
Usually, storing and retrieving from Local-storage is done through JavaScript but Polymer team has made a custom element you can use to make this process more Declarative.
Using the core-localstorage element:
<core-localstorage name="HOW YOU ACCESS THIS DATA" value="{{THE ACTUAL DATA YOU WANT TO STORE}}"></core-localstorage>
name attribute is how you access this data, every peice of data you store has to have a name with which you can set or get it's value through.
value attribute is the actual data you want to store, it can be an array, object, number or a string.
More documentations about core-localstorage and localstorage can be found at:
https://www.polymer-project.org/0.5/docs/elements/core-localstorage.html
http://diveintohtml5.info/storage.html
I am using the angularJS frontend framework and nodejs/express as a backend server to send and receive JSON. The backend sent a large JSON object to the frontend and I was wondering if I could download the JSON object from the frontend in CSV format.
The data is stored as json in an scope variable: $scope.data in an angular controller. Then I converted the data to a string in CSV format in the variable $scope.CSVdata. How do I get the CSVdata to download from the client browser?
I know nodejs can be set up to send a file in CSV format but it would be nice to keep the backend a clean JSON api.
Referencing this post I've thrown together quick demonstration on how this may be done using AngularJS:
JavaScript Demo (Plunker)
I've wrapped the referenced Base64 code in a service, and use it in the following way:
$scope.downloadCSV = function() {
var data = Base64.encode($scope.CSVData);
window.location.href = "data:text/csv;base64," + data;
};
There are some disadvantages to this method however as mentioned in the comments. I've pulled out some bullet points from the Wikipedia page on this subject. Head over there for the full list.
Data URIs are not separately cached from their containing documents (e.g. CSS or HTML files), therefore the encoded data is downloaded
every time the containing documents are re-downloaded.
Internet Explorer 8 limits data URIs to a maximum length of 32 KB. (Internet Explorer 9 does not have this limitation)
In IE 8 and 9, data URIs can only be used for images, but not for navigation or JavaScript generated file downloads.[7]
Base64-encoded data URIs are 1/3 times larger in size than their binary equivalent. (However, this overhead is reduced to 2–3% if the
HTTP server compresses the response using gzip)
Data URIs do not carry a filename as a normal linked file would. When saving, a default filename for the specified MIME type is
generally used.
[ . . . ]
I'm writting an application in Sencha-Touch 1.1 and I want to add localization to strings.
I've thought (but not implemented) of two ways.
Create seperate JSON files for each language (en-US.json, el-GR.json
etc) and use a proxy and a store to load the data, changing each
time the proxy url (json file destination). The problem is that I don't know how to extract the data from the store afterwards.
Create a global JSON object which then I inflate (parse the json file
and turn it into an object). The problem here is that I cannot seem to find a way to parse a JSON file without using a reader/proxy combo.
Is there any optimal solution for localizing strings in sencha-touch?
A common approach is to extract all of your strings into class level properties and have separate locale files which override these classes and their string properties.
For example, if I had a panel like this:
MyApp.MyPanel = Ext.extend(Ext.Panel, {
myPanelContent: 'This is your text to be translated...',
initComponent: function(){
Ext.apply(this, {
html: this.myPanelContent
});
MyApp.MyPanel.superclass.initComponent.call(this)
}
});
And then you would have a locale file along the lines of:
Ext.override(MyApp.MyPanel, {
myPanelContent: 'This is a translation of my text to another language'
});
You can then either load the correct locale file when your app is loaded (after the views themselves have been loaded) or dynamically load the locale files during runtime (this would require logic to update each of the views with the current value).
Hope this makes sense, give me a shout if it doesn't!
Stuart
Using firefox, I can store extension preferences using Components.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
What interface can I use to store preferences in Chrome? And do they get overwritten on an extension update?
Thanks
You can use the localStorage API. See http://code.google.com/chrome/extensions/options.html for an example of building an options page with this, but most simply you can do:
localStorage['foo'] = 'bar'; // Store data
var foo = localStorage['foo']; // Get data
This data won't be wiped out on extension update, either.
The new HTML5 feature to persist data locally (localStorage) should help you here.
In addition to coockies, now there are session and local storage objects, as well as, a simple version of relational database (all storing data on your local harddisk).
One hint when storing/retrieving objects to localStorage ... it is a simple implementation of the Map interface, so the safest way to persist your object is by serializing them via JSON.stringify function and parse retrieved string with JSON.parse.