title: Ionic 4 store formdata and sync on internet connectivity
body: <p>I have an application where I need to capture the dogs in offline mode. I have used the <strong>formdata</strong> because I am sending images along with the remaining data. I am using the below code to store the HTTP request.</p>
  
  <pre><code>storeRequest(url, type, data) {
     this.sharedService.presentToast('Your data is stored locally because you 
     seem to be offline.');
  
     let action: StoredRequest = {
        url: url,
        type: type,
        data: data,
        time: new Date().getTime(),
        id: Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5)
     };
  
     return this.storage.get(STORAGE_REQ_KEY).then(storedOperations =&gt; {
        let storedObj = JSON.parse(storedOperations);
  
        if (storedObj) {
            storedObj.push(action);
        } else {
            storedObj = [action];
        }
  
        return this.storage.set(STORAGE_REQ_KEY, JSON.stringify(storedObj));
      });
   }
  </code></pre>
  
  <p>Here I am storing all the requests. When I am trying to retrieve the data, I am getting an empty object. That's why I am not able to sync the data to the server. I have used the below code to sync the requests.</p>
  
  <pre><code>checkForEvents(): Observable&lt;any&gt; {
  return from(this.storage.get(STORAGE_REQ_KEY)).pipe(
    switchMap((storedOperations: any) =&gt; {
      let storedObj = JSON.parse(storedOperations);
      console.log(storedObj);
      if (storedObj &amp;&amp; storedObj.length &gt; 0) {
        console.log(storedObj);
        return this.sendRequests(storedObj).pipe(
          finalize(() =&gt; {
            this.sharedService.presentToast('Local data succesfully synced to 
            API!');
            this.storage.remove(STORAGE_REQ_KEY);
          })
        );
      } else {
        console.log('no local events to sync');
        return of(false);
      }
    })
  )
  }
  </code></pre>
  
  <p>**Edit - **
  Now my question is what is good practice to store the data?? Where can we store the formdata??</p>