So, basically, I need to upload a single image, save it to localStorage, then display it on the next page.
Currently, I have my HTML file upload:
<
document.getElementById('file').addEventListener('change', (e) => {
const file = e.target.files[0];
const reader = new FileReader();
reader.onloadend = () => {
// convert file to base64 String
const base64String = reader.result.replace('data:', '').replace(/^.+,/, '');
// store file
localStorage.setItem('wallpaper', base64String);
// display image
document.body.style.background = `url(data:image/png;base64,${base64String})`;
};
reader.readAsDataURL(file);
});
Example CodePen