Forum Discussion

Sukanth's avatar
Sukanth
Explorer | Level 4
6 years ago
Solved

is there a way we can resume downloads from where it left ?

Hi Guys, 

I wrote code using dropbox java sdk to download all the files in dropbox to my NAS (Network-attached storage). The data is huge . I tried to make the process faster using thread pool executor. However, when I abruptly close the program or when a fatal error occurus it corrupts the files that were in progress. Is there a way that we can delete the files that were not fully copied at the time of the fatal error? 

below is the draft code .. a lot of improvements can be made to it. 

https://github.com/sukanth/Dropbox

7 Replies

  • Sukanth's avatar
    Sukanth
    Explorer | Level 4
    6 years ago

    like the file is not fully downloaded. The output stream is interrupted in the middle and the whole image data is not written into the file because of the interruption. Is there a way that we can keep track of the files that were not fully downloaded and retry them again?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    6 years ago

    For cleaning up after failed operations, if an API call fails when you're using the Java SDK, it should raise an exception you can catch so you can perform whatever cleanup you need, such as deleting local files. 

    For restarting downloads, you can actually use DbxDownloadStyleBuilder.range to restart a download at whatever point in the file you need. There's an example of using that in test test code here.

  • Sukanth's avatar
    Sukanth
    Explorer | Level 4
    6 years ago

    Partially downloaded file

    when I say partially downloaded. I mean like the one in the above picture .when I stop the program abruptly this happens because the output stream is interrupted before the file is fully written on disk.  Can you suggest anything to handle this case?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    6 years ago

    Yes, it looks like in that case you've only written a portion of the file, so you could check how much of the file you did write, and then use DbxDownloadStyleBuilder.range to download just the rest of the file.

    Also, if it's helpful, you can use the "Content Hash" feature, available in the Java SDK as FileMetadata.contentHash, to verify if you've successfully downloaded the full and correct file contents.

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API
Make connections with 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!