When I use tdlib,call the api that download the file,like this;
TdApi.DownloadFile downloadFile = new TdApi.DownloadFile(file.id, 1);
Client.send(downloadFile,new new Client.ResultHandler() {
@Override
public void onResult(final TdApi.Object object) {
if (object instanceof File) {
File file = (File) object;
if (fileId == file.id) {
Bitmap bitmap = ImageUtils.decodeScaleImage(file.local.path, Constants.screenWidth, Constants.screenHeight);
if (bitmap != null) {
image.setImageBitmap(bitmap);
EaseImageCache.getInstance().put(file.local.path, bitmap);
} else {
image.setImageResource(R.drawable.ease_default_image);
}
}
}
}
}
});
The moment the code is called, the file is returned immediately,
but the returned file is not downloaded. like this:
[ 3][t 4][1523697175.945602179][Td.cpp:4642][!Td][&td_requests] Sending result for request 150: File {
id = 104
size = 120644
expectedSize = 120644
local = LocalFile {
path = ""
canBeDownloaded = true
canBeDeleted = false
isDownloadingActive = true
isDownloadingCompleted = false
downloadedPrefixSize = 0
downloadedSize = 0
}
remote = RemoteFile {
id = "AgADBQAD_6cxG9hoWFbNvrl1hz0jQUhc0zIABFDY4wYFsFFxT8cDAAEC"
isUploadingActive = false
isUploadingCompleted = true
uploadedSize = 120644
}
}
At this time, the file is still downloading, but you have returned the file.
Yes, exactly this behavior is described in a description of the method: "Asynchronously downloads a file from the cloud. updateFile will be used to notify about the download progress and successful completion of the download. Returns file state just after the download has been started". So, you need to handle UpdateFile to found when a file downloading is completed, or when a downloading has failed and isn't active anymore.
There is still a moment when the file is in the process of downloading. Still there is a state when the downloading is hanging.
But in general, the @levlam professional is right.
@liaoyu1992 Please make as many experiments as possible. Then we will think with you about how to use it. Next, we will edit the code tdlib, if there is such a need.
P.S.
I think the lion can be wrapped like that in the promise.
OK, I saw the updatefile callback, but it's unreasonable to just return the undownloaded file.
local = LocalFile {
path = ""
canBeDownloaded = true
canBeDeleted = false
isDownloadingActive = true
isDownloadingCompleted = false
downloadedPrefixSize = 0
downloadedSize = 0
}
information about the state of the remote file
remote = RemoteFile {
id = "AgADBQAD_6cxG9hoWFbNvrl1hz0jQUhc0zIABFDY4wYFsFFxT8cDAAEC"
isUploadingActive = false
isUploadingCompleted = true
uploadedSize = 120644
}
Perhaps they are already in the local database, and you can select them bypassing the status checking functionality. But this should already be checked.
The most important thing: wait for the answers of professionals
💪
Yes, exactly this behavior is described in a description of the method: "Asynchronously downloads a file from the cloud. updateFile will be used to notify about the download progress and successful completion of the download. Returns file state just after the download has been started". So, you need to handle UpdateFile to found when a file downloading is completed, or when a downloading has failed and isn't active anymore.
I can't understand. Code snippet to handle asynchorous downloads plz. I used UpdateFile in the result handler of DownloadFile. But it runs only once after the download has been started. Then I didn't receive any updates further.
@Dhina17 downloadFile returns file. updateFile are sent independently as updates all the time. They must be handled by update handler and not downloadFile result handler.
If you don't care about download progress and other file state changes, you can pass synchronous == true parameter to downloadFile request.
@Dhina17
downloadFilereturnsfile.updateFileare sent independently as updates all the time. They must be handled by update handler and notdownloadFileresult handler.If you don't care about download progress and other file state changes, you can pass
synchronous== true parameter todownloadFilerequest.
I need to care about progress. Can you give some examples how to handle file state changes?
Most helpful comment
OK, I saw the updatefile callback, but it's unreasonable to just return the undownloaded file.