B4J Library Dropbox SDK V2

Dropbox.png



This is a begin of a wrap for the Dropbox JAVA SDK
The Library is based on my v0.4 from the B4A Library. I´ve made an B4J Version out of it now.
The Library is beta.

It is a request for the community too to parcitipate to this project doing test or writing documentation for the objects.

List of connected Tutorials:
- Dropbox SDK V2 - Uploading big files to Dropbox
- Dropbox SDK - get informed about changes in the used Dropbox

Though it is a Link to a B4A Thread the same applies with the B4J Version so the Tutorial can be used.


DropboxV2
Comment:
The Dropbox library allows you to communicate with Dropbox
Author: DonManfred (wrapper)
Version: 0.42 (wraps the SDK dropbox-core-sdk-3.0.7)

Wrapped Objects so far
  • DbxAuth
  • DbxClientV2
  • DbxHost
  • Dimensions
  • DbxRequestConfig
  • DbxUserAuthRequests
  • DropboxV2
  • DbxUserFilesRequests
  • FileMetadata
  • FolderMetadata
  • FolderSharingInfo
  • GpsCoordinates
  • Mediainfo
  • MediaMetadata
  • Metadata
  • RelocationPath
  • DbxUserSharingRequests
  • MemberSelector
  • SharedFileMetadata
  • SharedFolderMetadata
  • SharedLinkMetadata
  • BasicAccount
  • FullAccount
  • DbxUserUsersRequests

The Download will always be here in Post #1 of the Thread.

Additional to the provided Library (xml and jar) you need to download:
1. dropbox-core-sdk-3.0.7 Copy the file to your additional libraries folder.
2. jackson-core-2.7.4.jar. Extract from the zip attached and copy the file to your additional libraries folder.
 

Attachments

  • DropboxV2jV0.4.zip
    107.6 KB · Views: 520
  • jackson-core-2.7.4.jar.zip
    233.4 KB · Views: 543
  • DropboxV2jV0.41.zip
    109 KB · Views: 574
  • DropboxV2jV0.42.zip
    112.7 KB · Views: 595
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Example Code to use in an Server App (using your App ID and using a generated AccessToken. For now i do not know how to create the OAuth-Flow to use.

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Dim Dropbox As DropboxV2
    Dim token As String
    Dim client As DbxClientV2
    Dim config As DbxRequestConfig
    Dim dbxFiles As DbxUserFilesRequests
    Dim dbxSharing As DbxUserSharingRequests
    Dim dbxUsers As DbxUserUsersRequests
    Dim clientId As String = "yourClientID"
    Dim token As String = "yourAccessToken"
    Private Button1 As Button
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
  
    config.Initialize("",token,clientId,"de-de",5)
    Dim dbxhost As DbxHost
    dbxhost.Initialize
    client.Initialize("Dropbox",config,token,dbxhost)
    dbxFiles = client.files
    dbxFiles.setEventname("dbxFiles")
      
    dbxSharing = client.sharing
    dbxSharing.setEventname("dbxSharing")
    dbxUsers = client.users
    dbxUsers.setEventname("dbxUsers")
    Dropbox.Initialize("")

    dbxFiles.listFolder("/",False,True,False,False,True)

End Sub
Sub dbxFiles_UploadProgress(sessionId As String, path As String, filename As String, uploaded As Long, size As Long)
    Log($"${filename} -> ${NumberFormat(uploaded / 1024, 0, 0)} KB /${NumberFormat(size / 1024, 0, 0)} kb -> ${NumberFormat(100 * (uploaded / size), 0, 2) } - Session ${sessionId}"$)
End Sub
Sub dbxFiles_UploadFinished(success As Boolean, metaObj As Object, sessionId As String)
    Dim meta As FileMetadata = metaObj
    Log($"dbxFiles_UploadFinished(${success} Session ${sessionId} -> ${meta})"$)
End Sub
Sub dbxSharing_listFolders(success As Boolean, folders As List, error As String)
    Log($"dbxSharing_listFolders(${success}, ${folders.Size}, ${error})"$)
    If folders.Size > 0 Then
        For i = 0 To folders.Size-1
            Dim meta As SharedFolderMetadata = folders.Get(i)
            Log(meta.PathLower&" -> "& meta.Name)
        Next
    End If
End Sub
Sub dbxSharing_AddFileMember(success As Boolean, members As List, error As String)
    Log($"dbxSharing_listFolders(${success}, ${members.Size}, ${error})"$)
End Sub
Sub dbxSharing_listMountableFolders(success As Boolean, folders As List, error As String)
    Log($"dbxSharing_listFolders(${success}, ${folders.Size}, ${error})"$)
End Sub
Sub dbxSharing_listReceivedFiles(success As Boolean, receivedFiles As List, error As String)
    Log($"dbxSharing_listFolders(${success}, ${receivedFiles.Size}, ${error})"$)
  
End Sub
Sub dbxSharing_listSharedLinks(success As Boolean, sharedLinks As List, error As String)
    Log($"dbxSharing_listFolders(${success}, ${sharedLinks.Size}, ${error})"$)
End Sub
Sub dbxSharing_SharedFolderMetadata(success As Boolean, meta As SharedFolderMetadata, error As String)
    Log($"dbxSharing_listFolders(${success}, ${meta.toString}, ${error})"$)

End Sub


Sub dbxFiles_DownloadFinished(success As Boolean, meta As FileMetadata, sessionId As String)
    Log($"dbxFiles_DownloadFinished(${success}, ${meta}, ${sessionId})"$)
End Sub
Sub dbxFiles_listFolder(success As Boolean, content As List, error As String)
    Log($"dbxFiles_listFolders(${success}, ${content.Size}, ${error})"$)
    If content.Size > 0 Then
        For i = 0 To content.Size-1
            Dim meta As Metadata = content.Get(i)
            Log(meta.toString)
        Next
    End If
  
End Sub
Sub dbxFiles_CopyBatch(success As Boolean, meta As Map, error As String)
  
End Sub
Sub dbxFiles_CopyBatchCheck(success As Boolean, meta As Map, error As String)
  
End Sub
Sub dbxFiles_CopyReference(metainfo As Map)
  
End Sub
Sub dbxFiles_CreateFolder(success As Boolean, meta As FolderMetadata, error As String)
  
End Sub
Sub dbxFiles_ListRevisions(success As Boolean, meta As Map, error As String)
  
End Sub
Sub dbxFiles_MoveBatch(success As Boolean, meta As Map, error As String)
  
End Sub
Sub dbxFiles_MoveBatchCheck(success As Boolean, meta As Map, error As String)
  
End Sub
Sub dbxFiles_Restore(success As Boolean, meta As FileMetadata, error As String)
  
End Sub

Sub dbxUsers_getAccount(account As BasicAccount)
    Log($"dbxUsers_getAccount(${account})"$)
End Sub
Sub dbxUsers_getAccountBatch(batch As List)
  
End Sub
Sub dbxUsers_getCurrentAccount(account As FullAccount)
    Log($"dbxUsers_getCurrentAccount(${account})"$)
  
End Sub
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Uploading of Big Files

B4X:
Sub Button1_Click
    Dim filename As String = "bremen.map"
    Dim path As String  = "E:\OSM"
    dbxFiles.uploadsession(path,filename,File.Size(path,filename),0,"","/testupload4j/", dbxFiles.WriteModeOVERWRITE)

End Sub

The Corresponding Events are as follows

B4X:
Sub dbxFiles_UploadProgress(sessionId As String, path As String, filename As String, uploaded As Long, size As Long)
    Log($"${filename} -> ${NumberFormat(uploaded / 1024, 0, 0)} KB /${NumberFormat(size / 1024, 0, 0)} kb -> ${NumberFormat(100 * (uploaded / size), 0, 2) } - Session ${sessionId}"$)
End Sub
Sub dbxFiles_UploadFinished(success As Boolean, metaObj As Object, sessionId As String)
    Dim meta As FileMetadata = metaObj
    Log($"dbxFiles_UploadFinished(${success} Session ${sessionId} -> ${meta})"$)
End Sub

I tested it with a 2.4GB big File. It does work as expected :D

uploadsession()
B4X-Video-Tutorials.zip -> 8,192 KB /2,468,663 kb -> .33 - Session AAAAAAABMf-2ITcAVqpJXQ
B4X-Video-Tutorials.zip -> 16,384 KB /2,468,663 kb -> .66 - Session AAAAAAABMf-2ITcAVqpJXQ
[...]
B4X-Video-Tutorials.zip -> 2,441,216 KB /2,468,663 kb -> 98.89 - Session AAAAAAABMf-2ITcAVqpJXQ
B4X-Video-Tutorials.zip -> 2,449,408 KB /2,468,663 kb -> 99.22 - Session AAAAAAABMf-2ITcAVqpJXQ
B4X-Video-Tutorials.zip -> 2,457,600 KB /2,468,663 kb -> 99.55 - Session AAAAAAABMf-2ITcAVqpJXQ
B4X-Video-Tutorials.zip -> 2,465,792 KB /2,468,663 kb -> 99.88 - Session AAAAAAABMf-2ITcAVqpJXQ
dbxFiles_UploadFinished(true Session AAAAAAABMf-2ITcAVqpJXQ -> {".tag":"file","name":"B4X-Video-Tutorials.zip","id":"id:qn6VkEYC6_gAAAAAAABlWw","client_modified":"2018-05-21T05:41:27Z","server_modified":"2018-05-21T05:41:27Z","rev":"1c04511fadbd8","size":2527911112,"path_lower":"/testupload4j/b4x-video-tutorials.zip","path_display":"/testupload4j/B4X-Video-Tutorials.zip","content_hash":"4dba6fea463cc3f94819b8be0044e59ba9854ceb6e21de014c3161bc98d78e13"})
{
".tag" : "file",
"name" : "B4X-Video-Tutorials.zip",
"id" : "id:qn6VkEYC6_gAAAAAAABlWw",
"client_modified" : "2018-05-21T05:41:27Z",
"server_modified" : "2018-05-21T05:41:27Z",
"rev" : "1c04511fadbd8",
"size" : 2527911112,
"path_lower" : "/testupload4j/b4x-video-tutorials.zip",
"path_display" : "/testupload4j/B4X-Video-Tutorials.zip",
"content_hash" : "4dba6fea463cc3f94819b8be0044e59ba9854ceb6e21de014c3161bc98d78e13"
}
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Getting an AccessToken in behalf of the User who authenticate the Request. This is working only in Version 0.41+ of the Library.

A json file with the clientId and the ClientSecret created which then can be used to generate a URL (authURL is a String).
B4X:
    Dim jgen As JSONGenerator
    jgen.Initialize(CreateMap("key": clientId, "secret": clientSecret))
    File.WriteString(File.DirApp,"credentials.json",jgen.ToString)
    authURL = auth.Initialize(clientId,token,File.Combine(File.DirApp,"credentials.json"))

You need to call this URL in a Webbrowser and follow the Authentication. At the end you´ll get an CODE. Copy the Code from the Webbrowser and use

B4X:
    Dim accesstoken As String = auth.AuthFinish(edtCode.Text,File.Combine(File.DirApp,"oauth.json"))
to get the AccessToken which you then can use to Initialize the Library with the right "Credentials"
B4X:
    Dim accesstoken As String = auth.AuthFinish(edtCode.Text,File.Combine(File.DirApp,"oauth.json"))
    If accesstoken <> Null And accesstoken <> "" Then
        kvs.Put("token",accesstoken)
        config.Initialize("",accesstoken,clientId,"de-de",5)
        Dim dbxhost As DbxHost
        dbxhost.Initialize
        client.Initialize("Dropbox",config,accesstoken,dbxhost)
        dbxFiles = client.files
        dbxFiles.setEventname("dbxFiles")
        dbxSharing = client.sharing
        dbxSharing.setEventname("dbxSharing")
        dbxUsers = client.users
        dbxUsers.setEventname("dbxUsers")
        dbxFiles.listFolder("",False,True,False,False,True)
    End If
 
Top