I'm making a chrome extension.User can upload images to the extension.To save the data of images I am using window.URL.createObjectURL()
.The problem is that I want to save the data about images in localStorage and use it again. But Browsers release the data automatically when the document is unloaded.
How can I use the data even when document is unloaded?
Asked
Active
Viewed 582 times
0

the_developer
- 747
- 2
- 7
- 17
-
See examples of reading the image contents into a string, then store it in any extension storage. – wOxxOm Jan 23 '20 at 06:53
1 Answers
0
Here's an example below on how to save data into LocalStorage but you can read more on the usage of LocalStorage here
// Storing into LocalStorage
localStorage.setItem("lastname", "Smith");
// Retrieving info from LocalStorage
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
// At the end, when you're done with the data. Just run
localStorage.clear();
So to answer you:
var imageData = window.URL.createObjectURL(image)
localStorage.setItem(imageData) // You can put this in a variable an use it.
UPDATE: If that doesnt work take a look at this, it wont be using LocalStorage as you want, but it could help.

Tumi
- 41
- 11