title: How to upload a file using api v2 dropbox in android studio?
body: <p>Specifically I am looking to upload a file with extension .xls</p>
  
  <p>I have a project that tries to do this, but the following error exists</p>
  
  <pre><code> E/AndroidRuntime: FATAL EXCEPTION: Thread-6
      Process: com.example.excelpromodel, PID: 12651
      java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/methods/HttpPut;
          at com.dropbox.client2.DropboxAPI.putFileRequest(DropboxAPI.java:2390)
          at com.dropbox.client2.DropboxAPI.putFileOverwriteRequest(DropboxAPI.java:1760)
          at com.dropbox.client2.DropboxAPI.putFileOverwrite(DropboxAPI.java:1726)
          at com.example.excelpromodel.SQLite2ExcelActivity$4.run(SQLite2ExcelActivity.java:267)
          at java.lang.Thread.run(Thread.java:764)
       Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.client.methods.HttpPut" on path: DexPathList[[zip file "/data/app/com.example.excelpromodel-pu6SR7F9dUiyu9bWnHwX8w==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.excelpromodel-pu6SR7F9dUiyu9bWnHwX8w==/lib/arm, /system/lib, /system/vendor/lib]]
          at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
          at com.dropbox.client2.DropboxAPI.putFileRequest(DropboxAPI.java:2390) 
          at com.dropbox.client2.DropboxAPI.putFileOverwriteRequest(DropboxAPI.java:1760) 
          at com.dropbox.client2.DropboxAPI.putFileOverwrite(DropboxAPI.java:1726) 
          at com.example.excelpromodel.SQLite2ExcelActivity$4.run(SQLite2ExcelActivity.java:267) 
          at java.lang.Thread.run(Thread.java:764) 
  </code></pre>
  
  <p>My code is: </p>
  
  <pre><code>public class SQLite2ExcelActivity extends AppCompatActivity {
  public static Button button1;
  public static String path = Environment.getExternalStorageDirectory().getPath() + "/Backup/";
  public static File Dir = new File(path);
  
  public void onClickBut1(View v) {
      UploadToDropboxFromPath(path + "test.txt", "excel/test.txt");
  }
  @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_sqlite_2_xl);
          button1 = findViewById(R.id.button1);
          initViews();
          AndroidAuthSession session = buildSession();
          dropboxAPI = new DropboxAPI&lt;AndroidAuthSession&gt;(session);
  }
  static DropboxAPI&lt;AndroidAuthSession&gt; dropboxAPI;
      private static final String APP_KEY = "";
      private static final String APP_SECRET = "";
      private static final String ACCESSTOKEN = "";
      private DropboxAPI.UploadRequest request;
      private AndroidAuthSession buildSession()
      {
          AppKeyPair appKeyPair = new AppKeyPair(APP_KEY, APP_SECRET);
          AndroidAuthSession session = new AndroidAuthSession(appKeyPair);
          session.setOAuth2AccessToken(ACCESSTOKEN);
          return session;
      }
      static final int UploadFromSelectApp = 9501;
      static final int UploadFromFilemanager = 9502;
      public static String DropboxUploadPathFrom = "";
      public static String DropboxUploadName = "";
      public static String DropboxDownloadPathFrom = "";
      public static String DropboxDownloadPathTo = "";
  
      private void UploadToDropboxFromPath (String uploadPathFrom, String uploadPathTo)
      {
          Toast.makeText(getApplicationContext(), "Upload file ...", Toast.LENGTH_SHORT).show();
          final String uploadPathF = uploadPathFrom;
          final String uploadPathT = uploadPathTo;
          Thread th = new Thread(new Runnable()
          {
              public void run()
              {
                  File tmpFile = null;
                  try
                  {
                      tmpFile = new File(uploadPathF);
                  }
                  catch (Exception e) {e.printStackTrace();}
                  FileInputStream fis = null;
                  try
                  {
                      fis = new FileInputStream(tmpFile);
                  }
                  catch (FileNotFoundException e) {e.printStackTrace();}
                  try
                  {
                      dropboxAPI.putFileOverwrite(uploadPathT, fis, tmpFile.length(), null);
                  }
                  catch (Exception e) {}
                  getMain().runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          Toast.makeText(getApplicationContext(), "File successfully uploaded.", Toast.LENGTH_SHORT).show();
                      }
                  });
              }
          });
          th.start();
      }
  
  
  
  @Override
      public void onActivityResult(int requestCode, int resultCode, Intent intent)
      {
          if (requestCode == UploadFromFilemanager)
          {
              final Uri currFileURI = intent.getData();
              final String pathFrom = currFileURI.getPath();
              Toast.makeText(getApplicationContext(), "Upload file ...", Toast.LENGTH_SHORT).show();
              Thread th = new Thread(new Runnable()
              {
                  public void run()
                  {
                      getMain().runOnUiThread(new Runnable()
                      {
                          @Override
                          public void run()
                          {
                              UploadToDropboxFromPath(pathFrom, "/db-test/" + DropboxUploadName + pathFrom.substring(pathFrom.lastIndexOf('.')));
                              Toast.makeText(getApplicationContext(), "File successfully uploaded.", Toast.LENGTH_SHORT).show();
                          }
                      });
                  }
              });
              th.start();
          }...
  }
  
  
  public String getPath(Context context, Uri contentUri) {
          Cursor cursor = null;
          try {
              String[] proj = { MediaStore.Images.Media.DATA, MediaStore.Video.Media.DATA, MediaStore.Audio.Media.DATA };
              cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
              int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
              cursor.moveToFirst();
              String s = cursor.getString(column_index);
              if(s!=null) {
                  cursor.close();
                  return s;
              }
          }
          catch(Exception e){}
          try {
              int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
              cursor.moveToFirst();
              String s = cursor.getString(column_index);
              if(s!=null) {
                  cursor.close();
                  return s;
              }
          }
          catch(Exception e){}
          try {
              int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
              cursor.moveToFirst();
              String s = cursor.getString(column_index);
              cursor.close();
              return s;
          }
          finally {
              if (cursor != null) {
                  cursor.close();
              }
          }
      }
  
      public SQLite2ExcelActivity getMain()
      {
          return this;
      }
  </code></pre>
  
  <p>AndroidManifest..</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.excelpromodel"&gt;
  
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.dropbox.client2.android.AuthActivity"
              android:configChanges="orientation|keyboard"
              android:launchMode="singleTask" &gt;
              &lt;intent-filter&gt;
  
                  &lt;data android:scheme="db-akg125xzg45a9gc" /&gt;
  
                  &lt;action android:name="android.intent.action.VIEW" /&gt;
  
                  &lt;category android:name="android.intent.category.BROWSABLE"/&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".SQLite2ExcelActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme" /&gt;
          &lt;activity
              android:name=".Excel2SQLiteActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>and dependences</p>
  
  <pre><code>implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'androidx.appcompat:appcompat:1.0.2'
  implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  implementation 'com.google.android.material:material:1.0.0'
  implementation 'com.ajts.androidmads.SQLite2Excel:library:1.0.4'
  implementation 'com.ajts.androidmads.sqliteimpex:library:1.0.0'
  implementation files('libs/dropbox-android-sdk-1.6.3.jar')
  implementation files('libs/json_simple-1.1.jar')
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'androidx.test:runner:1.2.0'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  </code></pre>
  
  <p>get and upload to Dropbox the xls file that is in the "Backup" path with a single button and not from the file manager. Thank you all</p>