Download binary data created from within an App on a desktop (or filesystem access)


#1

Hi guys, How would I simply download data from within an app? (For arguments sake a BIN file or a DAT file, but one with a full range of ascii values).

In this specific case, the data is created real-time by the app run in chrome on a desktop and is largely a processed extract from volt. Pls note that although the app is volt hosted, I don’t consider it a volt question as I’m interested to know how one does it even without volt.

If it sounds like a daft question that is covered elsewhere, forgive me but as soon as google “nsbasic download” you can imagine I am flooded with down topics from trials to adverts…


#2

It’s actually a very good question. AppStudio runs inside the browser’s sandbox, which prevents web apps from reading or writing your computer’s filesystem. (If you think about it, you really don’t want random web pages to be able to do this!)

Tell us a bit more about how you want to use the data.


#3

I’m aware of some old FileSystem links which are probably now irrelevant due to security… Eg: https://www.nsbasic.com/desktop/info/technotes/TN09.htm and https://stackoverflow.com/questions/2383985/copying-files-using-nsbasic-ce-7-0 , and I know about things like https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/ , but all that seems like a sledgehammer nut approach…


#4

Hi thanks, our msgs just crossed. Agreed about the security issues. My client just needs a file that he would then re-process into charts. The data is just logs, but does contain odd chars like SOH, TAB, VTAB, CR. What I envisage is the client clicking a button saying (eg) “download extract”. For me, this is only needed for a Windows / Chrome environment. Cheers


#5

The first two links are for NS Basic/Desktop and NS Basic/CE, both of which are completely unrelated to AppStudio.

An approach which might work nicely is to write the files out into a Dropbox folder using the DropBox API.
http://wiki.nsbasic.com/Using_Dropbox_to_save_files

You can also use Google Drive:
http://wiki.nsbasic.com/Google_Drive_API

It has the option of writing the data out as a spreadsheet.


#6

Fair enough … no simpler method then?

I should have said I’ve reviewed Dropbox and GDrive & they are too complex. My client won’t set up a GDrive or fiddle around with dropbox every time. :slight_smile:

What I was hoping for is an ability to add in a bit of HTML somewhere (I don’t know how as yet) that furnishes a link, and I just return maybe all the contents of my volt, an extract saved internally as a string or as an object, etc, and the browser facilitates the download as normal.

Can you confirm no such thing is possible within reason? Thanks :slight_smile:


#7

That brings another way to do this to mind. Have a look at this:


#8

Ah – well done! The best link was https://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side … which was one of the linked topics on your page.

Here is a tested sample from that link working in NSB…

Function button_onclick()
JavaScript
  var data = [["name1", "city1", "some other info"], ["name2", "city2", "more info"]];
  var csvContent = "data:text/csv;charset=utf-8,";
  var dataString;
  data.forEach(function(infoArray, index){

     dataString = infoArray.join(",");
     csvContent += index < data.length ? dataString+ "\n" : dataString;

  }); 
  //'use JavaScript's window.open and encodeURI functions to download the CSV file

  var encodedUri = encodeURI(csvContent);
  window.open(encodedUri);
End JavaScript
End Function

…Instant download in chrome (desktop) when you click the button. (Does nothing in a phone tho’).
Update: This limits to 2097152 bytes (2^21) of encoded length. Larger gives “network error”.


#9

Glad it’s working!

Note this comment on that page from Walter Tross, highlighting a problem.


#10

…Thanks. His prob is just related to how he extracts grid data I believe. The 2MB limit is a nuisance (chrome I assume) tho’.

While I have your ear, any hints on how to do the reverse and upload data in the same chrome desktop environment?