Closed rehanzo closed 3 years ago
Greetings.
Tdlib uploads (and downloads) files asynchronous. When you uploading files you need to listen updates (see read_updates example) and handle Update::File(UpdateFile)
messages. Each of them containts expected_size
field and RemoteFile::uploaded_size
. With that fields you can check uploading progress. So, when progress=100% you can stop listening updates.
Also I see that you call std::thread::sleep(std::time::Duration::from_secs(5))
. It's not correct in case of async rust. You have to call tokio::time::sleep(...).await
.
Great, you helped me figure it out. Thanks!
If I try to upload a file right before the end of the program, the file is unable to be uploaded before the program ends. If I add some sleep time, then the file gets through. What I am aiming to figure out now is how I would keep the program from ending before the file is uploaded, without sleeping for an arbitrary amount of time, hoping the file is uploaded before then. With the following code, the chosen file doesn't upload in time:
With the following code, the file (couple hundred kb in size) gets through, the only difference being the addition of 5 seconds of sleep:
Again, I would like to avoid sleeping for an arbitrary amount of time, and optimally have the program block while its uploading, and then continue when the file has uploaded, but I am not sure how to go about this. Thanks in advance.