Using Dropbox API to upload a file with Android

前端 未结 5 515
庸人自扰
庸人自扰 2020-12-08 15:31

How can I upload a File (graphic, audio and video file) with Android using the Dropbox API to Dropbox? I followed the tutorial on the Dropbox SDK Android page and could get

5条回答
  •  醉话见心
    2020-12-08 16:29

    According to the latest documentation of dropbox API V2:

    // Create Dropbox client
        val config = DbxRequestConfig.newBuilder("dropbox/java-tutorial").build()
        client = DbxClientV2(config, getString(R.string.token))
    
    // Uploading file
        FileInputStream(file).use { item ->
            val metadata = client.files().uploadBuilder("/${file.absolutePath.substringAfterLast("/")}")
                    .uploadAndFinish(item)
        }
    

    And if you want to overwrite file then add this to client:

    .withMode(WriteMode.OVERWRITE)
    .uploadAndFinish(item)
    

提交回复
热议问题