小编Ami*_*ole的帖子

PWA 离线时的图像存储

我正在为我现有的托管网站构建手动 PWA(不使用框架 IONIC、React 等)。我的基本要求是我想从我的手机相机中捕捉照片。但条件是: 1. 当我拍摄图片时,我将完全离线。2.我想把它上传到服务器意味着数据库中。但是当我离线时,我想将其存储在 localstorage 中,当我在 3 天后重新上线时,它将恢复剩余的内容并自动将图像上传到服务器。

我尝试使用 javascript 但没有得到那么多。我想要的基本方法是:

if(camera clicked)->
   if(upload btn clicked)-> 
        if(device is online)-> 
           upload to the server;
           (**or I can call one function here which can upload the image to server.)
        else if(device is offline)->
           upload to localstorage;
//again when device gets online I will call one **function(which is I am calling from **) in constructor which get executed everytime when site is reloaded or app is opened. 

My ** function will …
Run Code Online (Sandbox Code Playgroud)

offline-mode local-storage ionic-framework progressive-web-apps

7
推荐指数
1
解决办法
3057
查看次数