I've got a problem with a javascript Filereader which returns the error Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'. one in two. Sometimes it works, but when i repeat the operation, it fails.
Here's the HTML
<div id="upload-button" class="fpd-btn-raised fpd-secondary-bg-color fpd-secondary-text-color">
<i class="fpd-icon-file-upload"></i><span>Insérer votre image</span>
</div>
<input type="file" id="my-custom-design-upload" class="btn btn-success" style="display:none;">
Here's the javascript
It's a div button that, when clicked, triggers a click on the input field
$('#upload-button').click(function(){
$('#my-custom-design-upload').trigger('click');
return false;
});
The function that calls the file Reader
function readfichier(e) {
if(window.FileReader) {
var file = e.target.files[0];
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
var image = new Image;
image.src = e.target.result;
image.onload = function() {// Do something}
}
}
And the call to that function
document.getElementById('my-custom-design-upload').addEventListener('change', readfichier, false);
Any idea ? Thanks