Skip to content

Instantly share code, notes, and snippets.

@molidev8
Created August 16, 2022 17:04
Show Gist options
  • Save molidev8/9cc786258658efcb68ba32633bb04136 to your computer and use it in GitHub Desktop.
Save molidev8/9cc786258658efcb68ba32633bb04136 to your computer and use it in GitHub Desktop.
Managing data with the Dropbox SDK
/**
* Uploads a file into the user's Dropbox
* @param input A [FileInputStream] to the file that is going to be uploaded
* @return true in case the upload went well, false otherwise
*/
fun uploadFile(input: FileInputStream): Boolean {
return try {
client?.files()?.uploadBuilder("/recipe-vault-backup.zip")
?.withMode(WriteMode.OVERWRITE)
?.uploadAndFinish(input)
true
} catch (e: DbxException) {
throw DbxException("Error uploading files ${e.localizedMessage}")
}
}
/**
* Downloads a file from the user's Dropbox
* @param output A [FileOutputStream] to the path where is going to be downloaded
*/
fun downloadFile(output: FileOutputStream) {
try {
client?.files()?.download("/recipe-vault-backup.zip")?.download(output as OutputStream)
} catch (e: DbxException) {
throw DbxException("Error downloading files ${e.localizedMessage}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment