private static void uploadFile(DbxClientV2 dbxClient, File localFile, String dropboxPath) {
        try (InputStream in = new FileInputStream(localFile)) {
            ProgressListener progressListener = l -> printProgress(l, localFile.length());

            FileMetadata metadata = dbxClient.files().uploadBuilder(dropboxPath)
                .withMode(WriteMode.ADD)
                .withClientModified(new Date(localFile.lastModified()))
                .uploadAndFinish(in, progressListener);

            System.out.println(metadata.toStringMultiline());
        } catch (UploadErrorException ex) {
            System.err.println("Error uploading to Dropbox: " + ex.getMessage());
            System.exit(1);
        } catch (DbxException ex) {
            System.err.println("Error uploading to Dropbox: " + ex.getMessage());
            System.exit(1);
        } catch (IOException ex) {
            System.err.println("Error reading from file \"" + localFile + "\": " + ex.getMessage());
            System.exit(1);
        }
    }
private static void uploadFile ( DbxClientV2 dbxClient , File localFile , String dropboxPath ) { try ( InputStream in = new FileInputStream ( localFile ) ) { ProgressListener progressListener = l -> printProgress ( l , localFile . length ( ) ) ; FileMetadata metadata = dbxClient . files ( ) . uploadBuilder ( dropboxPath ) . withMode ( WriteMode . ADD ) . withClientModified ( new Date ( localFile . lastModified ( ) ) ) . uploadAndFinish ( in , progressListener ) ; System . out . println ( metadata . toStringMultiline ( ) ) ; } catch ( UploadErrorException ex ) { System . err . println ( "Error uploading to Dropbox: " + ex . getMessage ( ) ) ; System . exit ( 1 ) ; } catch ( DbxException ex ) { System . err . println ( "Error uploading to Dropbox: " + ex . getMessage ( ) ) ; System . exit ( 1 ) ; } catch ( IOException ex ) { System . err . println ( "Error reading from file \"" + localFile + "\": " + ex . getMessage ( ) ) ; System . exit ( 1 ) ; } }
Uploads a file in a single request. This approach is preferred for small files since it
eliminates unnecessary round-trips to the servers.

@param dbxClient Dropbox user authenticated client
@param localFIle local file to upload
@param dropboxPath Where to upload the file to within Dropbox