Forum Discussion

sesha's avatar
sesha
Explorer | Level 4
6 years ago

Upload from Android application

I am uploading files from android phone to my Dropbox. The path/directory where I am writing is Apps/p19

my upload code does the following: But this never succeeds. 

mDBApi.putFile("Apps/p19/t.csv",inputStream, filename.length(), null, null);

 Is my path wrong or am i making any mistake in the putFile call ?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    It looks like there are a few issues here:

    1. Based on "mDBApi.putFile", it looks like you're using an old and now retired Dropbox API (v1) and SDK. You should instead use Dropbox API v2. For accessing Dropbox API v2 from Android, we recommend using the official Dropbox API v2 Java SDK. There's an example Android app using it here. For uploading files, you can use the upload method.
    2. When specifying a non-root path, e.g., to indicate where the uploaded file should go, the path should start with a "/".
    3. If your app is registered for the "app folder" permission, you shouldn't include the "/Apps/<app folder name>" portion of the path. When making a call using an access token for an app with the app folder permission, the Dropbox API will automatically translate it to be relative to the app folder. So, you should just supply a path like "/t.csv".
    • sesha's avatar
      sesha
      Explorer | Level 4

      Thanks. it worked with v2 api

    • aliazaz's avatar
      aliazaz
      New member | Level 2

      How can I upload files to a specific folder in android

      • aliazaz's avatar
        aliazaz
        New member | Level 2

        got the answer:

        FileInputStream(file).use { item ->
        val metadata = client.files().uploadBuilder("/$rootPATH/${file.absolutePath.substringAfterLast("/")}")
        .uploadAndFinish(item)
        }