angular-file-upload icon indicating copy to clipboard operation
angular-file-upload copied to clipboard

Add timeout to xhr request

Open FelipeBarrosCruz opened this issue 9 years ago • 4 comments

Set timeout into XMLHttpRequest Object

FelipeBarrosCruz avatar Jul 22 '16 13:07 FelipeBarrosCruz

What about of the iframeTransport?

nervgh avatar Jul 28 '16 20:07 nervgh

What is happening to this request?

nikryden avatar Mar 22 '17 13:03 nikryden

@nikryden it is frozen. We should handle this option for non XHR requests somehow.

nervgh avatar Mar 22 '17 15:03 nervgh

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.

DanRamGim avatar Sep 11 '17 21:09 DanRamGim