L
L
lanvin lanvin072016-04-30 22:20:17
Android
lanvin lanvin07, 2016-04-30 22:20:17

How to save a picture to Local Storage in Android?

On the desktop, I save the picture in Local Storage in Base64 (Fig. 1), then I pull it out and display it (Fig. 2) - everything is OK.
When I build this application in Phonegap, I see that the image type is not saved and the image, accordingly, is not displayed (the lost fragment is highlighted in Fig. 3).
If I manually add the missing fragment image/png;, then the picture is displayed normally.
What Phonegap is doing with JS, what is happening is not clear, because. I don't see the project code.
Fig.1 178a17882098444482c940b458f2f44e.pngFig.2 bc5435643cd94fa6bf0423c8afb6a353.pngFig.3 8221231c21154bd7ad136ad97f2f7ed2.png
Why is this happening and how to solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lanvin lanvin07, 2016-05-03
@lanvin07

Code
It seems that we managed to solve the problem, but with the help of a crutch :-)
index2.html:

$( document ).ready(function() {
      $("#localText").text( localStorage.getItem("TextEntryName") );
      var ls = localStorage.getItem("ImageEntryName");
      var from = 5;
      var to = 5000000;
      $newls = ls.substring(from,to);
      console.log("$newls = " + $newls);
        $newnewls = "data:image/jpeg;" + $newls;
        console.log("$newnewls = " + $newnewls);
        $("#localImage").attr("src", $newnewls );
    });

Here I'm trimming the first 5 characters of "data:" then adding "data:image/jpeg;".
Crutch! Only works for jpg.
And it is not known whether this will work on all Android.
Why does cropping still occur?!
upd . On one English-language forum, I received an answer that the problem is due to the fact that the mobile browser cannot recognize the resource type (mymetype), and they recommended using Crosswalk.

N
Nicholas, 2016-05-01
@ACCNCC

Local Storage is not for pictures! for pictures and other large files use pouchdb https://pouchdb.com/guides/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question