Save JSON file information to database

Asked

Viewed 353 times

1

I think about the possibility of a Web system saving information from a register in a JSON file on the client’s device, which would later be sent to the BD. This will happen when the client is in an environment where it is not possible to access the internet at the time of the registration to synchronize with the online BD. Is there any divergence or best practice for this implementation?

  • 1

    web system... has to be on the internet right... otherwise it has to be a mobile system that saves in a sqlite bank for example... then make the synchronization...

  • You can work with the Indexeddb and synchronize with your remote BD whenever necessary.

  • 1

    @Rovannlinhalis not necessarily. One can easily persist given in the browser’s Storage area. It is a simple, key/value system, but it serves very well.

  • @Rovannlinhalis agree with your statement. I thought of something like ASP.NET Core Self Host to be hosted on the device itself, because I believe the system will be installed on tablets with Android.

  • @It’s also a possibility to do this. But I need the size of the Storage browser not to exceed with the amount of information.

  • 1

    @Thiagolunardi’s solution looks good, but it depends on the purpose... I mistakenly thought it was temporary data, but the limitation happens in size: "At least 5MB": https://www.w3schools.com/html/html5_webstorage.asp

  • 1

    Anyway, I would go by a compiled application, in Xamarim for example...

  • @Rovannlinhalis I think will be the best.

Show 3 more comments

1 answer

3

This is not complicated, especially being Web system.

All means of environment client have an area of Storage - even browsers. Usually these areas of Storage work simply, with key and value - key value.

Vc can implement something like the following pseudo code:

sendData = (data) => {
  _http.send(data, 
    (response) => { success(response); },
    (error) => { _retryStorage.add(data); });
};

So have a service periodically doing something like:

var data = _retryStorage.pop();
data && sendData(data);

So if you haven’t been able to upload the data to the server, play Torage to recover later. So another asynchronous service is "listening" to this line, and if there’s something there, try to re-send.

Remember that this is just a pseudo code, there is much to develop to work as expected, but it is a good way to be followed.

  • Nice idea. Thanks for the tip Thiago.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.