Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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!)
}
}
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.
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)")
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.
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).
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.
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.
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.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
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!