0

I wan to store the event object of the input type file in local Storage but when i convert the object into JSON String it returns an empty object.

var image = document.getElementById('image');
    image.addEventListener('change', function (e) {
        var img = e.target.files[0];
        localStorage.setItem('img', JSON.stringify(img))
        var getImg = localStorage.getItem('img');
        console.log(JSON.parse(getImg));

    }); 
Osama Xäwãñz
  • 437
  • 2
  • 8
  • 21
  • Log `img`. What's the output? – ibrahim mahrir Jan 20 '17 at 05:25
  • See [How to save an image to localStorage...](http://stackoverflow.com/questions/19183180/how-to-save-an-image-to-localstorage-and-display-it-on-the-next-page) – Dehli Jan 20 '17 at 05:27
  • 1
    Possible duplicate of [How to save an image to localStorage and display it on the next page?](http://stackoverflow.com/questions/19183180/how-to-save-an-image-to-localstorage-and-display-it-on-the-next-page) – Dehli Jan 20 '17 at 05:29

1 Answers1

-1

If the image object is the binary contents of an image file then it cannot be stringified to a valid JSON.

Perspectivus
  • 972
  • 1
  • 9
  • 22