Hello I am using this library here to upload files to my own Dropbox acount:
https://www.b4x.com/android/forum/threads/dropbox-sdk-v2-java.74019/#content
I followed the instructions HERE and HERE
In my case, I usually want to upload small files to Dropbox so I used upload instead of uploadsession:
This is how my code looks:
When I run it and press the button , it will only say: "upload()" in the logs , then it will crash with an error:
If I comment out dbxFiles.upload and use uploadsession, it will only say "uploadsession()" in the log, but it doesn't crash.
https://www.b4x.com/android/forum/threads/dropbox-sdk-v2-java.74019/#content
I followed the instructions HERE and HERE
In my case, I usually want to upload small files to Dropbox so I used upload instead of uploadsession:
This is how my code looks:
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim auth As DbxAuth
Dim Dropbox As DropboxV2
Dim client As DbxClientV2
Dim config As DbxRequestConfig
Dim dbxFiles As DbxUserFilesRequests
Dim dbxSharing As DbxUserSharingRequests
Dim dbxUsers As DbxUserUsersRequests
Dim token As String = "...."
Dim DropboxEnabled As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
Log("Token available. Dropbox enabled")
config.Initialize("",token,"","en-us",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")
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 Button1_Click
Dim path As String = File.DirInternal
Dim filename As String = "test.txt"
File.WriteString(path, filename, "Hello world!")
dbxFiles.upload(path, filename, "/Hello/", False, False)
' dbxFiles.uploadsession(path,filename,File.Size(path,filename),0,"","/OSM/", dbxFiles.WriteModeADD)
End Sub
When I run it and press the button , it will only say: "upload()" in the logs , then it will crash with an error:
java.lang.RuntimeException: Object should first be initialized (FileMetadata).
If I comment out dbxFiles.upload and use uploadsession, it will only say "uploadsession()" in the log, but it doesn't crash.
Last edited: