Query the content size and cancel the query in the Progress Monitor #456
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:
|
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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.
Beta Was this translation helpful? Give feedback.
All reactions