Query the content size and cancel the query in the Progress Monitor #456
Skillkiller
started this conversation in
General
Replies: 3 comments 4 replies
|
Yes, if the progress monitor were to throw an exception it will stop the download. You will end up with a HttpResponse with a status of 200 (the servers response), and a parsing error and a null body. Something like this: |
1 reply
|
Thank you for the quick reply. This is exactly what I needed. I can cancel the requests directly should the content length header be submitted and if not, I can download up to maximum limit. |
0 replies
try {
Unirest.get("http://speedtest.tele2.net/1GB.zip").downloadMonitor((field, fileName, bytesWritten, totalBytes) -> {
throw new RuntimeException("Too big!");
}).asBytesAsync().get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}The example shown above runs completely through for me without error? I would have assumed that the download aborts. Also by means of sout I get no outputs. It looks to me as if the download monitor is not called? I use the version 3.13.11 |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello,
is there any way to find out the file size before the download starts? I only want to download files smaller than 50MB.
Furthermore, is it possible to cancel the request via the ProgressMonitor? I process the requests asynchronously.
All reactions