Save, retrieve and upload data to a remote server --- (AngularJs / Ionic)

Thank you very much for all your lessons that have helped us a lot and helped us in many ways. Please, I have problems in my hands to solve, although I am new to angular / ionic.

1) I have a form containing several input data for collecting personal information, such as names, gender, DOB, classes, etc. At the bottom of the form, I have an image tag and a button for displaying and capturing the image, respectively. I was able to capture and display the captured image.

STATEMENT OF THE PROBLEM:

1) I would like to keep all personal information, including captured images on local storage. What for? due to a bad network.

2) I would like to receive the stored information and image and download the remote server.

Please, I would be so grateful if you can illustrate this with a simple and short tutorial, as you wish. Thanks again.

+2
source share
1 answer

You might want to use the Cordova sqlite datastore. Link

To do this,

Install the plugin in the folder with the ion project via:

cordova plugin add https://github.com/brodysoft/Cordova-SQLitePlugin.git

Get ng-cordova.min.js and add ur to the javascript directory, add the following line of code to your index.html.

<script src="<your folder>/ng-cordova.min.js"></script>

Paste angular (app.js) into your module via:

angular.module('starter', ['ionic', 'ngCordova'])

Create a database through:

.controller('YourController', function(....., $cordovaSQLite){

 var db = $cordovaSQLite.openDB("database.db");
 $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS form (id integer primary key, name text, address text, telephone text)");

Insert example:

 $scope.insert = function(name, text, telephone) {
        var query = "INSERT INTO form (name, text, telephone) VALUES (?,?,?)";
        $cordovaSQLite.execute(db, query, [name, text, telephone]).then(function(res) {
            console.log("success!");
        }, function (err) {
            console.error(err);
        });
    }

Then your image file can be stored as blob and have fun! (

+6
source

Source: https://habr.com/ru/post/1616306/


All Articles