Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone.
i try using local storage for speed up my site to load image and audio file,
so i set my Pic File with java Script like this:
JavaScript
var req = new XMLHttpRequest();
        req.onload = function (e) {
            var arraybuffer = oReq.response;
        }
        req.open("GET", '/zTest.jpg');
        req.responseType = "arraybuffer";
        req.send();
        req.addEventListener('readystatechange', function () {
            if (req.readyState === 4) {
                localStorage.setItem('photo', req.response);
            }
        });


What I have tried:

in other page i use this code to return my file
JavaScript
var img = new Image();
            img.src = localStorage.photo;
            $('.imagearea').html(img);

but it don`t show Pic and my img src like this:
HTML
<img src="[object ArrayBuffer]">

note: i know local storage file size most less 5 Mb
Posted
Comments
F-ES Sitecore 14-Aug-18 4:44am    
You can't reference local storage items via a url, you can only manipulate them via js. Secondly I don't think you can even store objects in local storage any more. To store an image you'd probably need some way of base64 encoding it, then setting the src of the img tage to be the base64 you retrieved from the local storage.

Embed base64

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900