angular-file-upload
angular-file-upload copied to clipboard
Add timeout option
We had a case where the upload never reached the server and was just hanging. It would be good if a timeout option could be added, so if this happens again an error is returned.
For _xhrTransport
this would just mean setting xhr.timeout = item.timeout
and then catching it with xhr.ontimeout = function () {}
Thanks
+1
@MattOakley , I think it may be useful :+1:
+1
+1
Hi! Can you explain how to use timeout in the plugin? I did not find any hooks to set it.
I tried implementing it at onBeforeUploadItem like this:
uploader.onBeforeUploadItem = function (item) {
xhr.timeout = item.timeout
xhr.ontimeout = function () { item.cancel();}
}
and I get the following error whenever I call "xhr":
RangeError: Maximum call stack size exceeded
at angular-file-upload.min.js:6
at Array.filter (
Could you help me please?
See https://github.com/nervgh/angular-file-upload/pull/657
I have just found my solution, you can add this lines on angular-file-upload.min.js
After this lines:
o = e._xhr = new XMLHttpRequest; if (e.disableMultipart ? t = e._file : (t = new F, f(e.formData, function (e) { f(e, function (e, n) { t.append(n, e) }) }), t.append(e.alias, e._file, e.file.name)), "number" != typeof e._file.size) throw new TypeError("The file specified is no longer valid");
And before this lines: o.upload.onprogress = function (t) { var o = Math.round(t.lengthComputable ? 100 * t.loaded / t.total : 0);
You can add your code, this is mine: e._xhr.timeout = 3600000; e._xhr.ontimeout= function(){e.isError = true; e.progress = 0; alert('El servidor no ha respondido, favor de intentarlo nuevamente')};
This makes the timeout of an hour long and it deletes the progress and show that you had an error, after that I send an alert.