In NSBasic, I see no direct way to just save some textual data to the hard drive on a desktop computer. I know NSBasic was made for app design, but isn’t there a direct way to just save data to a file on a local desktop machine?
I’ve looked at all the docs and the closest thing I have found is using AJAX with a server - I don’t want or need to GET or POST data just yet and will NOT be using any database files.
AppStudio is based on Web technology and runs in a browser instance. One of the security features of browsers is that the pages or apps you run should not be able to mess up your computer.
That’s why they don’t allow the creation of files - you can imagine the mischief which would be possible.
Can you explain more about what you’re trying to accomplish?
I really can’t explain much in a public forum, but I need to somehow save this data either to my local computer or encrypted here in code that cannot be intercepted and then sent to a server. I don’t care if encrypted code is intercepted en route because it’s already unreadable.
If you only need to save your data as a text file, this works in Chrome. Does not work in Safari.
function saveContent(fileContents, fileName) //Chrome only
{
var link = document.createElement('a');
link.download = fileName;
link.href = 'data:,' + fileContents;
link.click();
}
Writing a file is a bit more complicated. Browsers don’t allow you to write directly to the computer’s filesystem. (Can you imagine what problems could happen if web pages were allowed to write files to the user’s computer?)
Helen’s suggestion is a good workaround. If you’re planning to run as a native app on Android or iOS, there are plugins to do this. For the Desktop, Electron makes this possible.