This is my html page:
<!DOCTYPE html>
<html lang="es">
<head>
<link rel="stylesheet" href="css/miestilos.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<div>
<input type="file" id="files" />
<output id="list"></output>
</div>
<script type="text/javascript" src= "js/app.js"></script>
</body>
</html>
And my script:
$(document).ready(function() {
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
var span = document.createElement('span');
document.getElementById('list').innerHTML='';
span.innerHTML = ['<img class="center" id="imagen" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
document.getElementById('list').insertBefore(span, null);
localStorage.setItem("imgSrc",document.getElementById('imagen').src);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
});
I need to save the src of the image so that when I go to a different page.html I can paint this image on canvas and manipulate it.
For certain images it works but for big images I miss this error when doing the instruction "localStorage.setItem (" imgSrc ", document.getElementById ('image'). src);":
Uncaught DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'imgSrc' exceeded the quota.
I understand that the src is too long to be stored in localStorage.
What I do on the other page is the following: var imgSrc = localStorage.getItem ("imgSrc");
var img = new Image ();
img.src = imgSrc;
It works for images but for others it gives me failure to save the src in the storage.
If someone knows how to solve it, I would appreciate it. Greetings.