Reputation: 2338
I'm attempting to find a way when an upload is initiated with XHR so I can do something; I looked around and read that .loadstart
was for when the request starts (which means what exactly?) and this is what I had:
function processUpload(file, postName, onLoadCallback, onErrorCallBack, onProgressCallBack, startCallBack)
{
var xhr = new XMLHttpRequest();
var fD = new FormData();
for(var i = 0; i < file.length; i++)
{
xhr.open("POST", "PATHHERE");
xhr.loadstart = startCallBack;
xhr.onload = onLoadCallback;
xhr.onerror = onErrorCallBack;
xhr.upload.onprogress = onProgressCallBack;
fD.append(postName, file[i]);
xhr.send(fD);
}
}
Also, I'm unsure if a for loop is the best way of going about doing multiple file uploads. I feel as though that could get heavy on the site. What is the better method of doing that?
Upvotes: 0
Views: 93
Reputation: 8413
Request starts when you call send. You may want to queue you files to limit concurrent uploads. Take a look at already existing file uploader implementation.
Look into source code for the html5 uploader if you want to write your own.
Upvotes: 2