Object saving in local file

Hello !
I would like to save some Objects contents in a local file.
How can I do this ?
JSON ? XML ? I’m not used to it …
Do you have hype example of this ?
My project is online : here
The purpose is to save the datas needed to make the graphic
Thank you for your suggestions !

Can you clarify what you’re trying to do? Save a text file to a computer based on the manipulations on the site? And then you could then upload that file to load the same shape?

Exactly !
Today, users could already save a screenshot of the Synthèse scene, locally on their machine.
In the same time, I would like to save a txt file containing few Object parameters in order to offer the possibility to redo the same graphics.
I’m far from a coding expert and I’m not used to XML or JSON file management …
I wonder if someone had the same problematic of data saving and could give me an hype example ?-)

For now, I try something like this (for write in a file) :

var fileName = getFilePrefix()+'Essai.chw';
var oeilIndex=0,pointNo=0, deviationSaved;
var somethingJSON = JSON.stringify(somethingToSave, null, '\t');  
	var jsonAsBlob = new Blob([somethingJSON], {type:'text/plain'});
  	var downloadLink = document.createElement("a");
	downloadLink.download = fileName;
	downloadLink.innerHTML = "Download File";
	if (window.webkitURL != null) {
    	// Chrome allows the link to be clicked
    	// without actually adding it to the DOM.
    	downloadLink.href = window.webkitURL.createObjectURL(jsonAsBlob);
	} else {
    	// Firefox requires the link to be added to the DOM
    	// before it can be clicked.
    	downloadLink.href = window.URL.createObjectURL(jsonAsBlob);
    	downloadLink.onclick = destroyClickedElement;
    	downloadLink.style.display = "none";

But I don’t know how to read it after ! …

Yup, this stuff is beyond me, but someone here might have some tips for you!
It would be helpful if you can share your Hype document.

just a question: why do you want to write a local file? What about localStorage, save on webserver or indexedDB? some link: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Client-side_storage

Is it simpler to write on the webserver rather than locally ?
(I’m a neo-coders : my question may be stupid !)
The goal is to permit contexte saving in order to allow the user replaying (retracing in our case)

The problem is we do not know what your real goal is in regards to when this data is to be used.
Same session, same day, some other day. Or even some other computer/location.

So to answer where or even how best to save/store the data is hard to answer without that.

I think json is in any case the best way to go. There are a few threads ( if you do a search) on how to write out or read json from a file.

Here is one for example along ( if I remember correctly a video explaining more on the concept )

1 Like

Thank you for this example : it helps a lot !