Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  191] [ 3]  / answers: 1 / hits: 34122  / 10 Years ago, sat, july 19, 2014, 12:00:00

I'm making a drag-and-drop file upload system for photo gallery uploads. This is my source code handling dropped files. This one works multiple files if I drop them one by one it works but when I drop more than one at the same time this error occures:



Uncaught InvalidStateError: Failed to execute 'readAsDataURL' on 'FileReader': The object is already busy reading Blobs.



function handleFiles(files)
{
var reader = new FileReader();
var formdata = new FormData();

$.each(files, function(i, j)
{
$(td.photos span.status).html(Processing file: +j.name);

formdata.append('file', j);

$.ajax({
url: uploadalbum.php,
type: POST,
dataType: json,
data: formdata,
processData: false,
contentType: false,
success: uploadfinished
});

reader.onload = handleReaderLoad;
reader.readAsDataURL(j);
});
}


Any ideas?


More From » jquery

 Answers
41

I think the error is already given to you.





Failed to execute 'readAsDataURL' on 'FileReader': The object is already busy reading Blobs





So the file reader is already busy but only when you drop multiple files? Then it is probably busy with the first file (and the second crashes).



When you put var reader = new FileReader(); in your jQuery each loop it will work like below:



$.each(files, function(i, j)
{
var reader = new FileReader();
$(td.photos span.status).html(Processing file: +j.name);

formdata.append('file', j);
.... <snip>

}

[#70138] Thursday, July 17, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
griffinr

Total Points: 242
Total Questions: 91
Total Answers: 105

Location: Indonesia
Member since Wed, Jul 7, 2021
3 Years ago
;