cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Swifty dropbox download file complete?

Swifty dropbox download file complete?

Christian T.16
New member | Level 1

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 7

Greg-DB
Dropbox Staff

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.16
New 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-DB
Dropbox Staff

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.16
New 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.16
New 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-DB
Dropbox Staff

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.16
New 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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Christian T.16 New member | Level 1
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?