Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Christian T.16
10 years agoNew member | Level 1
Swifty dropbox download file complete?
Hi,
How can I determine when the file I'm downloading is complete? Is there a callback or something?
I'm using the Swifty dropbox API to download a video file (provided by the tutorial...)
client.files.download(path: dbPath, destination: destination).response
{
response, error in
if let (metadata, url) = response {
} else {
print(error!)
}
}
7 Replies
Replies have been turned off for this discussion
- Greg-DB10 years ago
Dropbox Community Moderator
Yes, the "response" callback method in the snippet you posted only fires once the operation is complete. If you get a response object back, the download succeeded. If you get an error object back, there was an error.
- Christian T.1610 years agoNew member | Level 1
Thanks but when I execute these print statements inside the block, it takes about 3-5 seconds to print the NSData to the console, so I can't play the video back until it finishes.
print("*** Download file ***")
let data = NSData(contentsOfURL: url)
print("Downloaded file data: \(data)")
- Greg-DB10 years ago
Dropbox Community Moderator
If you're referring to a delay before the callback is called, that's expected because the file has to be downloaded from the Dropbox API servers over the network.
If you're referring to a delay when calling NSData.contentsOfURL, that also seems reasonable, since the entire (possibly large) file is being loaded from disk into memory.
If you mean to play the downloaded video in a media player, you should pass the file URL to the media player instead of loading the raw data into memory and printing it.
- Christian T.1610 years agoNew member | Level 1
I'm actually getting the response back immediately, then the data from the video comes streaming across. There's no delay. In other words, it's giving me a response back when the file isn't fully downloaded.
I'm not actually trying to play the video just yet. I'm trying to notify the user when it's fully downloaded, but the response is notifying too soon (coming back to quickly with file data not fully downloaded).
- Christian T.1610 years agoNew member | Level 1
i decided to call a completionHandler after printing the NSData to console. That seems to introduce the delay of fully downloading the file before the completionHandler is called.
- Greg-DB10 years ago
Dropbox Community Moderator
I can't seem to reproduce the behavior you're describing, but I'm glad to hear you got this working the way you wanted.
- Christian T.1610 years agoNew member | Level 1
Thanks, I'm gonna try a bigger video. A friend suggested that it might be fully downloading that fast and what I'm seeing in the console is queued data.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!