Created
August 16, 2022 17:04
-
-
Save molidev8/9cc786258658efcb68ba32633bb04136 to your computer and use it in GitHub Desktop.
Managing data with the Dropbox SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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