Skip to content
Advertisement

Save FormData to Indexdb

The below code is what take final action to save the data to the target DB.

JavaScript

Now I am building an offline app, where when no internet is available I would like to save this request to indexdb. I have the whole setup. All I want to know how can I save a FormData instance to indexdb so that I can later fetch it from indexdb and send it to server for permanent storage. I need some ideas. I tried some google but I don’t see any direct answer to the following question. I am using idb npm plugin. The below update function I will be using to as an interface to talk to the db.

JavaScript

Advertisement

Answer

You could extract the FormData through the Body.formData() method, and then retrieve its content by getting this FormData’s entries and store these to IDB:

JavaScript

Too bad we can’t just put POST requests in the Cache API, it would have been a lot cleaner…

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement