Then please file a formal issue in the official API Issue Tracker:
Issues · SketchUp/api-issue-tracker · GitHub
Some servers do not send a total size for the resource being downloaded.
If this is the case, the total will not be more than zero (and usually == -1.)
So you can only calculate the percentage when the total is supplied.
Ex:
pattern = "Downloading: %d (%#.1f%%)"
request.set_download_progress_callback do |current, total|
if total > 0
percentage = ((current / total.to_f)*100).round(1)
puts format(pattern, current, percentage)
else
puts "Downloading: #{current}"
end
end
REF:
There is also a means in HTTP requests to ask the server ahead of time what size a resource is going to be. Not all servers will return the value . In this case the request is a HEAD type.
REF:
Open API Issue:
opened 03:17PM - 28 Apr 20 UTC
bug
Ruby API
SketchUp
logged
### SketchUp Ruby API Issue
**[`Sketchup::Http::Request.set_download_progress… _callback`](https://ruby.sketchup.com/Sketchup/Http/Request.html#set_download_progress_callback-instance_method) is near worthless.**
The **`total`** block parameter is always **`-1`** (making comparison to the **`current`** block parameter worthless.)
>**EDIT**: [TH believes](https://forums.sketchup.com/t/async-download-a-file/123421/17) that the **`total`** value being **`-1`** is a documentation issue.
> Ie, that [`RFC2616 sec14.13`](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13) states that _"Any **Content-Length** greater than or equal to zero is a valid value."_ and so **`-1`** indicates that the server at the URL did not return a **`"Content-Length"`** header that could be passed into the block as the 2nd parameter.
In addition, the block runs the final time after download is complete ... **BUT,** the status is **erroneously** still **`STATUS_PENDING`** in the final call even though the `current` parameter is equal to the full download size (of the `response.body`.)
> **EDIT**: This "might" also be happening because the test URL uses GitHub, which is not returning a **`"Content-Length"`** header for a HEAD request.
We need another URL to test with. Perhaps a EW model URL ?
We **can** get the full download from the `response` body in the `request#start` callback block.
In order for a workaround, we'd need to find some way to figure out ourselves what the download size is in order to have something to compare the current parameter to within the progress callback in order to make it useful and display a progress bar.
Platform: Windows 10
Bugged in SU2017, SU2018, SU2019 and SU2020.
**Reproduce by**: run `DLTEST.go` and observe console output.
* [DLTEST_v3.zip](https://github.com/SketchUp/api-issue-tracker/files/4546734/DLTEST_v3.zip)
----
**NOTE: Jira issue created: SU-40832** by @hilliard-sketchup on 1 OCT 2018
Another forum topic on this subject:
Can the Sketchup::Http module be used to asynchronously download files?
It looks like so considering the set_download_progress_callback method.
But where is the file stored once downloaded?
Is there more information somewhere?