B4A Class Dropbox API V2. All HTTP! All using httputils2

Update April 2017:
Google has changed the ability to use a Webview to get an OAuth-Token. Due to this change it no longer works to get an OAuth-Token using a Webview.
This library is not useable anymore except if you use the Lib only using YOUR token which is hardcoded in your app. This will work.
But if you need to get Access to a Users Dropbox then you can´t use this lib anymore. I suggest to switch to my Java-Wrap for the Drobox Api V2. Here you are able to get an OAuth-Token as this lib does not depend on a Webview.

-----------------------------------------------------------------------------

As you can read here Dropbox has decided to deprecate the Sync and Datastore APIs over the next 12 months. Drobox has now released an new preview site for the new V2 API

Dropbox released an API Explorer for their V2 api.
See the announce too for the explorer.

--------------------------------------------------------------------------------------------------------------------------------------------

This thread is about the HTTP version of the new Dropbox V2 api.
See the documentation here: https://www.dropbox.com/developers-preview/documentation/http#documentation

The attached B4A Library is using this new HTTP Api

The Library is available as Library (jar + xml). Please download DropboxV2_libraryfiles_v091.zip to get the files. Extract the content to your additional Librariespath

Please download DropboxHTTPv2librarysource_V0.91 if you want to change the class. Use this project and compile it to a library to get the correct jar and xml created by yourself
In most cases you dont need this one.

DropboxHttpAPI
Author:
DonManfred <msy1912@gmail.com>
Version: 0.93
  • DropBox
    Events:
    • Account (meta As Map)
    • AddFolderMember (meta As Map)
    • Copy (meta As Map)
    • CreateFolder (path_lower As String, name As String)
    • CreateSharedLink (meta As Map)
    • CurrentAccount (meta As Map)
    • Delete (meta As Map)
    • Delta (meta As Map)
    • DownloadLink (meta As Map)
    • FileDownloadFinished (session As Map)
    • FileSearch (result As Map)
    • FileUpload (session As Map)
    • FolderMetadata (meta As Map)
    • GetSharedLinks (meta As Map)
    • GetURLJob (meta As Map)
    • JobStatus (meta As Map)
    • LatestCursor (meta As Map)
    • ListFolder (meta As Map)
    • ListFolders (folders As Map)
    • ListfolderMembers (meta As Map)
    • MetaData (meta As Map)
    • MountFolder (meta As Map)
    • Move (meta As Map)
    • Preview (meta As Map)
    • RelinquishFolderMembership (meta As Map)
    • RemoveFolderMember (meta As Map)
    • Revisions (revs As Map)
    • RevokeSharedLink (meta As Map)
    • SaveURL (meta As Map)
    • ShareFile (meta As Map)
    • ShareFolder (folders As Map)
    • ShareJobStatus (meta As Map)
    • SpaceUsage (meta As Map)
    • Thumbnail (bmp As Bitmap, Tag As Object)
    • TransferFolder (meta As Map)
    • UnmountFolder (meta As Map)
    • UnshareFolder (meta As Map)
    • UpdateFolderMember (meta As Map)
    • UpdateFolderPolicy (meta As Map)
    • UploadSessionFinish (session As Map)
    • UploadSessionStatus (session As Map)
    Methods:
    • IsInitialized As Boolean
      Tests whether the object has been initialized.
    • add_folder_member (shared_folder_id As String, email As String, dropbox_id As String, access_level As String, quiet As Boolean, custom_message As String) As String
      Allows an owner or editor (if the ACL update
      policy allows) of a shared folder to add
      another member.
      For the new member To get access To all the
      functionality For this folder, you will need
      To call mount_folder on their behalf.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • check_job_status (async_job_id As String) As String
      Returns the status of an asynchronous job.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • check_share_job_status (async_job_id As String) As String
      Returns the status of an asynchronous job for
      sharing a folder.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • copy (fromPath As String, toPath As String) As String
      Copy a file or folder to a different location in
      the user's Dropbox.
      If the source path Is a folder all its contents
      will be copied.
    • createfolder (path As String) As String
      Create a folder at a given path.
    • createsharedlink (path As String, shorturl As Boolean) As String
      Create a shared link.
      If a shared link already exists For the given path,
      that link Is returned.

      Note that in the returned PathLinkMetadata, the
      PathLinkMetadata.url field Is the shortened URL
      If CreateSharedLinkArg.short_url argument Is set
      to True.
      Previously, it was technically possible To break
      a shared link by moving Or renaming the corresponding
      File Or folder. In the future, this will no longer
      be the Case, so your app shouldn't rely on this
      behavior. Instead, if your app needs to revoke a
      shared link, use revoke_shared_link.
    • delete (path As String) As String
      Not yet finished....
    • download (path As String, destpath As String, destfile As String) As String
      Download a file from a user's Dropbox.
    • getaccount (accountID As String) As String
      Get information about a user's account.
      The Event
      <code>Example:
      dbx.GetAccount("454365363464")</code>
    • getcurrentaccount As String
      Get information about the current user's account.
      <code>Example:
      dbx.GetCurrentAccount()</code>
    • getdelta (cursor As String, locale As String, includeMediaInfo As Boolean) As String
    • getdownloadlink (path As String) As String
    • getfoldermetadata (SharedFolderID As String, IncludeMembership As Boolean) As String
      Returns shared folder metadata by its folder ID.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • getlatestcursor (path As String, recursive As Boolean) As String
      A way to quickly get a cursor for the folder's state.
      Unlike list_folder, list_folder/get_latest_cursor doesn't
      return any entries. This endpoint is for app which only
      needs to know about new files and modifications and doesn't
      need to know about files that already exist in Dropbox.
    • getmetadata (path As String) As String
      Returns the metadata for a file or folder.
    • getpreview (path As String) As String
      Get a preview for a file. Currently previews are only
      generated for the files with the following extensions:
      .doc, .docx, .docm, .ppt, .pps, .ppsx, .ppsm,
      .pptx, .pptm, .xls, .xlsx, .xlsm, .rtf
    • getrevisions (path As String, revlimit As Int) As String
      Return revisions of a file
    • getsharedlinks (path As String) As String
      Returns a list of LinkMetadata objects for this user,
      including collection links.
      If no path Is given Or the path Is empty, returns a
      list of all shared links For the current user,
      including collection links.
      If a non-empty path Is given, returns a list of all
      shared links that allow access To the given path.
      Collection links are never returned in this Case.

      Note that the url field in the response Is never the shortened URL.
    • getsharefilelink (path As String) As String
    • getspaceusage As String
      Get the space usage information for the current user's account.
      <code>Example:
      dbx.GetSpaceUsage()</code>
    • getthumbnail (path As String, format As String, size As String) As String
      Gets a thumbnail for an image.
      Parameters
      format - jpeg (default) Or png.
      For images that are photos, jpeg should be preferred,
      While png Is better For screenshots And digital art.

      size One of the following values (default: s):
      value dimensions (px)
      xs 32x32
      s 64x64
      m 128x128
      l 640x480
      xl 1024x768
    • geturljob (JobID As String) As String
    • getversion As String
    • initialize (CallbackModule As Object, EventName As String, AccessToken As String, debug As Boolean) As String
      Initialize the Dropbox Class.
      Parameters
      CallbackModule
      EventName
      AccessToken
      debug
      <code>Example:
      dbx.GetAccount("454365363464")</code>
    • listfolder (path As String) As String
      Returns the contents of a folder.
    • listfoldercontinue (cursor As String) As String
    • listfoldermembers (SharedFolderID As String) As String
      Returns shared folder membership by its folder ID.
      Warning: This endpoint is in beta and is subject to
      minor but possibly backwards-incompatible changes.
    • listfoldermemberscontinue (cursor As String) As String
    • listfolders As String
    • listfolderscontinue (cursor As String) As String
      Once a cursor has been retrieved from list_folder_members,
      use this to paginate through all shared folder members.

      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • logversioninfo As String
    • mount_folder (SharedFolderID As String) As String
      The current user mounts the designated folder.
      Mount a shared folder For a user after they have
      been added As a member. Once mounted, the shared
      folder will appear in their Dropbox.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • move (fromPath As String, toPath As String) As String
      Move a file or folder to a different location in
      the user's Dropbox.
      If the source path Is a folder all its contents
      will be moved.
    • relinquish_folder_membership (SharedFolderID As String) As String
      The current user relinquishes their membership
      in the designated shared folder and will no
      longer have access to the folder. A folder
      owner cannot relinquish membership in their
      own folder.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • remove_folder_member (shared_folder_id As String, email As String, dropbox_id As String, leave_a_copy As Boolean) As String
      Allows an owner or editor (if the ACL update policy
      allows) of a shared folder to remove another member.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • revokesharedlink (url As String) As String
      Revoke a shared link.
      This API Is only supported For full dropbox apps.
    • saveurl (url As String, destpath As String) As String
    • search (path As String, searchquery As String) As String
      Searches for files and folders.
    • sharefolder (Path As String, MemberPolicy As String, acl_update_policy As String, shared_link_policy As String, forceAsync As Boolean) As String
      Parameters:
      path String
      The path To the folder To share. If it does Not exist, Then a new one Is created.

      member_policy String
      MemberPolicy Who can be a member of this shared folder.
      Policy governing who can be a member of a shared folder.
      Only applicable To folders owned by a user on a team.
      The value will be one of the following datatypes.
      New values may be introduced As our API evolves.

      "team" Only a teammate can become a member.
      "anyone" Anyone can become a member.

      acl_update_policy String
      AclUpdatePolicy Who can add And remove members of this shared folder.
      Policy governing who can change a shared folder's access control
      list (ACL). In other words, who can add, remove, or change the
      privileges of members.The value will be one of the following
      datatypes. New values may be introduced as our API evolves.

      "owner" Only the owner can update the ACL.
      "editors" Any editor can update the ACL.
      This may be further restricted To editors on the same team.

      shared_link_policy String
      The policy To apply To shared links created For
      content inside this shared folder.
      Policy governing who can view shared links.The value
      will be one of the following datatypes. New values
      may be introduced As our API evolves.

      "anyone" Links can be shared with anyone.
      "members" Links can only be shared among
      members of the shared folder.

      force_async Boolean
      Whether To force the share To happen asynchronously.
      The default For this field Is False.
    • transfer_folder (SharedFolderID As String, toDropboxID As String) As String
      Transfer ownership of a shared folder to a
      member of the shared folder.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • unmount_folder (SharedFolderID As String) As String
      The current user unmounts the designated folder.
      They can re-mount the folder at a later time using
      mount_folder.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • unsharefolder (SharedFolderID As String, leaveacopy As Boolean) As String
      Allows a shared folder owner to unshare the folder.
      You'll need to call check_job_status to determine
      if the action has completed successfully.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • update_folder_member (shared_folder_id As String, email As String, dropbox_id As String, access_level As String, quiet As Boolean, custom_message As String) As String
      Allows an owner or editor of a shared folder to
      update another member's permissions.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • update_folder_policy (SharedFolderID As String, MemberPolicy As String, acl_update_policy As String, shared_link_policy As String) As String
      Update the sharing policies For a shared folder.
      Warning: This endpoint Is in beta And Is subject To
      minor but possibly backwards-incompatible changes.
    • upload (localpath As String, localFilename As String, dstpath As String, dstfilename As String) As String
      Create a new file with the contents provided
      in the request. Do Not use this To Upload a
      File larger than 150 MB. Instead, create
      an Upload session with UploadSessionStart.
    • uploadsessionstart (sessionMap As Map) As String







First we need to initialize the Class
B4X:
dbx.Initialize(Me,"DropBox","access_token",True)
If you want to use the class just "with your dropbox" then you can create a access_token in the Dropbox App console.

You can find an example of not using pre-created access_token in Post #45 of this thread.. It is using the OAuth2 Flow to get access to a users Dropbox.

In order they are listed on the Previewdocumentation site i´ll post Examples (or just description on how to) for each of the used endpoints.

B4X:
dbx.GetAccount("dbid:AAB2cfhttqMg1RjLLRlFzYWWoY6lUpWKsKo")
' Event
Sub DropBox_Account(meta As Map)
    Log("Dropbox_Account: "&meta)
End Sub
Get information about a user's account. In this case it wil get informations about MY (DonManfred) dropboxaccount.

B4X:
dbx.GetCurrentAccount
' Event
Sub DropBox_CurrentAccount(meta As Map)
    Log("Dropbox_CurrentAccount: "&meta)
End Sub
Get information about the current user's account. It will result in giving YOUR (the developer) account.

B4X:
dbx.GetSpaceUsage

' Event
Sub DropBox_SpaceUsage(space As Map)
    Log($"DropBox_SpaceUsage(${space})"$)
End Sub
Get the space usage information for the current user's account.


B4X:
dbx.GetMetadata("/b4arulez.gif")

' Event
Sub DropBox_MetaData(meta As Map)
    Log("Dropbox_MetaData: "&meta)
End Sub
Returns the metadata for a file or folder.



B4X:
dbx.Listfolder("/Export")
' dbx.ListfolderContinue is called from the result-sub
' automatically if there are more results

' Event
Sub DropBox_ListFolder(meta As Map)
    Log("Dropbox_Listfolder: "&meta)
    Dim cursor As String = meta.Get("cursor")
    Dim has_more As String = meta.Get("has_more")
    Dim entries As List = meta.Get("entries")
    For Each colentries As Map In entries
        Dim path_lower As String = colentries.Get("path_lower")
        Dim name As String = colentries.Get("name")
        filelistfolder.Add(name)

        Dim tag As String = colentries.Get(".tag")
    Next
    If has_more = True Then
        dbx.ListfolderContinue(cursor)
    Else
        Log("No more files")
        Log($"FilesInFolder(${filelistfolder.Size})"$)
        For i = 0 To filelistfolder.Size-1
            LogColor(filelistfolder.Get(i),Colors.Yellow)
        Next
        Dim resulting_files As List = WildCardFilesList(filelistfolder,"*.csv",True,True)
        For i = 0 To resulting_files.Size-1
            LogColor(resulting_files.Get(i),Colors.Green)
        Next

        'kvs.PutObject("filelistfolder", filelistfolder)
    End If

End Sub
Returns the contents of a folder.
NOTE (from Dropbox): We're definitely going to streamline this interface.




B4X:
dbx.GetLatestCursor("/",False)

' Event
Sub DropBox_LatestCursor(meta As Map)
    Log("DropBox_LatestCursor()")
    Dim cursor As String = meta.Get("cursor")
    longpollcursor = cursor
    kvs.PutSimple("longpollcursor",cursor)
    Log("longpollcursor set: "&cursor)
End Sub
A way to quickly get a cursor for the folder's state. Unlike list_folder, list_folder/get_latest_cursor doesn't return any entries. This endpoint is for app which only needs to know about new files and modifications and doesn't need to know about files that already exist in Dropbox.






B4X:
dbx.Download("/9-patch-assets.zip",File.DirDefaultExternal,"9patch.zip")


' Event is missing as yet.
Download a file from a user's Dropbox.
As i´m writing this forumpost i see that this method is missing a event when finished. It is working and saving the file as you can see it in the logs but the event is missing. TODO


B4X:
    Dim session As Map
    session.Initialize
    session.Put("srcpath","/storage/emulated/0/Download")
    session.Put("srcfile","20150716151904894.pdf")
    session.Put("dstpath","/Export")
    session.Put("dstfile","20150716151904894.pdf")
    session.Put("offset",0)
    session.Put("packetsize",16384)
    dbx.UploadSessionStart(session)
' This is raising multiple events.
Sub DropBox_UploadSessionStatus(session As Map)
    Dim pro As Double = session.Get("offset")/(session.Get("filesize")/100)
    Label1.Text = session.Get("offset")&" / "&session.Get("filesize")&" -> "&pro
End Sub
Sub DropBox_UploadSessionFinish(session As Map)
    Log("DropBox_UploadSessionFinish()")
    Log(session)
End Sub
Start a new upload session. This is used to upload a single file with multiple calls. I´ve tried it with files up to 20mb but should work with 500mb as well.


B4X:
dbx.Upload(extsdcard,"app-release.apk","/","app-releaseTEST.apk")
' Event
Sub DropBox_FileUpload(meta As Map)
    Log("Dropbox_FileUpload: "&meta)

    Dim path As String = meta.Get("path_lower")
    Log("Path: "&path)
    Dim rev As String = meta.Get("rev")
    Log("Rev: "&rev)
    Dim name As String = meta.Get("name")
    Log("Name: "&name)
    Dim size As Int = meta.Get("size")
    Log("FileSize: "&size)
    Dim client_modified As String = meta.Get("client_modified")
    Dim server_modified As String = meta.Get("server_modified")
    Log("ClientModified: "&client_modified)
    Log("ServerModified: "&server_modified)
End Sub
Create a new file with the contents provided in the request. Should only be used for small files. Maybe up to for example 2mb... It is using ONE httputilscall to transfer the file.


B4X:
dbx.Search("","libmysql")
' Event
Sub DropBox_FileSearch(meta As Map)
    Log("Dropbox_FileSearch: "&meta)
End Sub
Searches for files and folders in your dropbox.



B4X:
dbx.CreateFolder("/Export")
' Event
Sub DropBox_Createfolder(path As String,filename As String)
    Log($"DropBox_Createfolder(${path},${filename})"$)
End Sub
Create a folder at a given path.
No file or folder may exist at the path. The parent folder will be created if it does not already exist (and so on). If the parent exists it must be a folder (and the same for any ancestor). If an ancestor is a shared folder it must have write access.

B4X:
dbx.delete(("/9-patch-assets.zip")
' Event
Delete the file or folder at a given path.
If the path is a folder all its contents will be deleted too.


B4X:
    ' Copy a FILE
    ' Source and Destination should point to a file
    'dbx.copy("/Export/b4arulez.gif","/copyofb4arulez.gif")

    ' Copy a FOLDER
    'dbx.copy("/Export","/copyfoldertest")
    ' will resulting in creating a folder copyfoldertest
    ' and then all files from Export will be copied to copyfoldertest/

' Event
Sub Dropbox_copy(copyinfo As Map)
    Log($"DropBox_copy(${copyinfo})"$)
End Sub

If the path is a folder all its contents will be deleted too.


B4X:
    ' Move  a FILE
    ' Move a FILE
    'dbx.move("/copyofb4arulez.gif","/newnameofb4arulez.gif")

    ' Move a FOLDER
    dbx.move("/copyfoldertest","/newdestfoldertest")

' Event
Sub Dropbox_move(moveinfo As Map)
    Log($"DropBox_copy(${moveinfo})"$)
End Sub


This method is NOT FINISHED as yet. DON´T USE it actually. TODO

B4X:
  dbx.GetThumbnail("/2000likes.png","png","s")
   'Parameters
   'format jpeg (default) Or png. For images that are photos,
   ' jpeg should be preferred, While png Is better For screenshots And digital art.
  '
  ' size One of the following values (default: s):
  'value   dimensions (px)
  ' xs     32x32
  ' s       64x64
  ' m       128x128
  ' l       640x480
  ' xl     1024x768

' Event
Sub Dropbox_Thumbnail(thumb As Bitmap, Tag As Object)
   Log($"DropBox_Thumbnail(${Tag})"$)
   iv1.Bitmap = thumb
End Sub
Get a thumbnail for an image.


B4X:
dbx.GetRevisions("/B4A/LibMySQL/MySQLExample.zip",100)
' Event
Sub DropBox_Revisions(revlist As Map)
   Log("DropBox_Revisions()")
   Log(revlist)
   Dim is_deleted As String = revlist.Get("is_deleted")
   Dim entries As List = revlist.Get("entries")
   For Each colentries As Map In entries
     Dim path As String = colentries.Get("path_lower")
     Dim revision As String = colentries.Get("rev")
     Dim name As String = colentries.Get("name")
     Dim client_modified As String = colentries.Get("client_modified")
     Dim size As Int = colentries.Get("size")
     Dim server_modified As String = colentries.Get("server_modified")
     Log($"FileRev(${path}):${revision}->${size} "$)
   Next


   'kvs.PutSimple("longpollcursor",cursor)
End Sub
Return revisions of a file

Update:: August, 20th, 2017
If you want to use Dropbox to connect to the USERS Dropbox (not YOURS) then you should look at the DropboxV2-OAuth2.zip example. It shows the way on how to get an Axccesstoken using the V2 endpoints.


The following methods are missing totally as yet: TODO

- Restore

TODO:

-

Dependencies:
- httputils2 (okHTTP)
- JSON
- RandomAcessFile
- KeyValueStore (used in example but not really needed by the class or Library)


This Class is open source and free to used and extended by anyone!

If you want to donate for my work building the class you can do it here:
 

Attachments

  • DropboxV2_version0.80.zip
    17.5 KB · Views: 274
  • DropboxV2_version0.85.zip
    17.7 KB · Views: 446
  • DropboxV2_libraryfiles_v093.zip
    19.6 KB · Views: 577
  • DropboxHTTPv2librarysource_V0.93.zip
    17.5 KB · Views: 495
  • DropboxV2-OAuth2.zip
    72.9 KB · Views: 271
Last edited:

Danbicky

Member
Licensed User
Don this is awesome. Do you pretty please have an example of using this?

My idea is to knock up a simple application that allows my students to access folders I store on drop box with lesson material in such as PDF files, word, excel etc, lesson plan over the academic year, assignment schedule etc. This would allow them to catch up with work if they miss lessons etc.

Would be gratefully appreciated if you have an example I can build from.

Thanks buddy

Dans
 

DonManfred

Expert
Licensed User
Do you pretty please have an example of using this?
See the Project in Post #1. Anything you need is there. You just need to call the Methods.
My idea is to knock up a simple application that allows my students to access folders I store on drop box with lesson material in such as PDF files
Just create a Folder in your Dropbox and create a ShareURL for it. Give the shareURL to all your students. They can access all the files inside this folder when using the link. You can use
B4X:
dbx.CreateSharedLink(path As String, shorturl As Boolean)
to create a sharedlink.

You students dont need to use my Class to access the files!

Maybe you should explain more in details what exactly you want to do.

PS: Welcome in our comunity!
 

Danbicky

Member
Licensed User
See the Project in Post #1. Anything you need is there. You just need to call the Methods.

Just create a Folder in your Dropbox and create a ShareURL for it. Give the shareURL to all your students. They can access all the files inside this folder when using the link. You can use
B4X:
dbx.CreateSharedLink(path As String, shorturl As Boolean)
to create a sharedlink.

You students dont need to use my Class to access the files!

Maybe you should explain more in details what exactly you want to do.

PS: Welcome in our comunity!

Thanks Don,

My aim is to create a student friendly application that allows them to follow the intensive lessons delivered. I lecture in advanced electronic engineering, delivering 7 different units over the academic year. Each unit has 30 delivery sessions of material taught over the period. Ideally I would like to create an app that allows the content to become visible after the lesson has been taught. This would then allow students to recap in detail prior to completing a summative assessment.

Dropbox is a good repository and very simple for me to publish material too. Any idea's on how I go about this would be brilliant, maybe you could suggest another option if Dropbox is not the ideal solution.

Big thanks again, I am really happy to become part of this great community, only of recent have I started to dabble with B4A although I do have a wealth of programming experience coding in assembler language for microcontrollers for over 20 years.

Dans
 

DonManfred

Expert
Licensed User
I lecture in advanced electronic engineering, delivering 7 different units over the academic year. Each unit has 30 delivery sessions of material taught over the period.
You are delivering an app for your students which they will use?
So basically you need to get rid of which lesson a student solved. Based on this you can give the user access to the specific file for the next lesson.

The basic logic behind this you need to build by yourself. But with dropbox you have an very very powerful "toy" in your hands. You should be able to build a solution with my class and a bit of own logic (and layout to the student which lessons are available, which ones the already solved, an so on)
Any idea's on how I go about this would be brilliant, maybe you could suggest another option if Dropbox is not the ideal solution.

Like i said above i think that Dropbox IS the right solution about the repository; you (your app) is able to get specific files and to download them for the student, showing the pdf is just calling an intent after you downloaded the file...

It´s needs a bit of "logic" to handle your special needs, yes. But you surely can use Dropbox as a good place to share documents of any type and size.

If you need help on building this solution with dropbox then please create a new Thread for this issue as it will be some discusses over there for it. I will try to help you if needed.

We should use THIS thread here for any Problems using my class.
 

Danbicky

Member
Licensed User
Don,

Awesome, I am heading in the right direction :)

Big thanks buddy, I will download your class and project and start to experiment. Good idea to start another thread based on this requirement. A big thanks for providing assistance with this, I do really think that a solution like this would help many lecturers and most importantly the students.

Kind regards

Dans
 

Danbicky

Member
Licensed User
Don,

Just a quick download and complie, I get the following error:

B4A version: 5.20
Parsing code. (0.04s)
Compiling code. Error
Error compiling program.
Error description: Unknown type: anywheresoftware.b4a.http.HttpClientWrapper.HttpUriRequestWrapper
Are you missing a library reference?
Occurred on line: 76
job.GetRequest.SetContentEncoding("text/plain")
Word: setcontentencoding

I have the OkHTTP lib

Any ideas on why it is unhappy?

Thanks Dans
 

DonManfred

Expert
Licensed User
Dropbox today released the new V2 API

Some new Methods are implemented inside the V2 (compared to the beta-2). Most of them regarding Shared folders, people who are bound to a shared folder and so on... See here for more details.

I will do an update of my Class in a few weeks... For the next three weeks i probably dont have the time to do an update ...
 

Rabbit

Member
Licensed User
Hi DonManfred,

I understand this code will allow me to intract wit the dropbox if it has been installed on the Android device?


So, If I want to access my files as login by username & password.. How I can do it?

Regards,
 

DonManfred

Expert
Licensed User
I understand this code will allow me to intract wit the dropbox if it has been installed on the Android device?
No. It communicates with DROPBOX.
So, If I want to access my files as login by username & password.
Create a app in dropbox

dropbox0048.png

generate access token for this app


copy the credentials. Use these credentials with the class.
 

Mahares

Expert
Licensed User
I will do an update of my Class in a few weeks... For the next three weeks i probably dont have the time to do an update ...
Eagerly anticipating your new Dropbox V2 class as the beta was very helpful. Do not let us down.
Thank you for being so reliable and essential driver of this forum.
 

DonManfred

Expert
Licensed User
I´m still working on the update.

'
' ========================
' API V2
' ========================
'
'
'users
'/get_account OK
'/get_current_account OK
'/get_space_usage OK
'/get_account_batch MISSING

'files
'/get_metadata OK
'/list_folder/longpoll MISSING
'/list_folder OK
'/list_folder/Continue OK
'/list_folder/get_latest_cursor OK
'/Download OK
'/upload_session/start OK
'/upload_session/append OK
'/upload_session/finish OK
'/Upload OK
'/Search OK
'/create_folder OK
'/Delete OK
'/permanently_delete MISSING
'/copy OK
'/move OK
'/get_thumbnail OK
'/get_preview NOT WORKING AS YET
'/list_revisions OK
'/restore MISSING
'

'sharing
'/get_shared_links OK
'/create_shared_link OK
'/revoke_shared_link OK
'/get_folder_metadata OK
'/list_folders OK
'/share_folder OK
'/update_folder_policy OK
'/unshare_folder MISSING
'/transfer_folder MISSING
'/unmount_folder MISSING
'/mount_folder MISSING
'/add_folder_member MISSING
'/check_share_job_status MISSING
'/check_job_status MISSING
'/remove_folder_member MISSING
'/update_folder_member MISSING
'/relinquish_folder_membership MISSING

' MISSING AT ALL
' /restore
' /get_account_batch
' /ListFolderLongpoll
'
' NOT WORKING:
' /get_preview
'
' ========================
' New in V0.90ß (12/04/15)
' sharing:
' ->get_shared_links
' ->create_shared_link
' ->revoke_shared_link
' ->get_folder_metadata
' ->list_folders
' ->share_folder
' ->update_folder_policy
'
' ========================
' New in V0.87ß (9/9/2015)
' - getsharedlinks(path as String)
' - CreateSharedLink(path As String, shorturl As Boolean)
 

wizard699

Active Member
Licensed User
But, in this versione, EVENT doesn't fire? I'm using UPLOAD .... but the event FILEUPLOAD doesn't fire
 

wizard699

Active Member
Licensed User
I cannot see any code you ae using. Without seeing it it is hard to give congrete answers.
It is working for me

Code:

Globals
------------
Dim dbx As DropBox


Activity_Create
-------------
dbx.Initialize(Me,"DropBox", "mytoken", False)
dbx.Upload( pathnomeDirLetture, CameraModule.fileTosend ,"/", CameraModule.fileTosend)


and then there is event ...
----------------------------

Sub DropBox_FileUpload(meta As Map)
Msgbox("Dropbox_FileUpload: "&meta,"Info")

End Sub


File UPLOAD goes ok ... and the file was send corrctly!
But event doesn't fire.


Thanks
 

DonManfred

Expert
Licensed User
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 dbx As DropBox
End Sub
Sub Activity_Create(FirstTime As Boolean)
    dbx.Initialize(Me,"DropBox","your key here",True)
    dbx.Upload(File.DirRootExternal,"overlay.png","/","overlay.png")
End Sub
Sub DropBox_FileUpload(meta As Map)
    Log("Dropbox_FileUpload: "&meta)
  
    Dim Path As String = meta.Get("path_lower")
    Log("Path: "&Path)
    Dim rev As String = meta.Get("rev")
    Log("Rev: "&rev)
    Dim name As String = meta.Get("name")
    Log("Name: "&name)
    Dim size As Int = meta.Get("size")
    Log("FileSize: "&size)
    Dim client_modified As String = meta.Get("client_modified")
    Dim server_modified As String = meta.Get("server_modified")
    Log("ClientModified: "&client_modified)
    Log("ServerModified: "&server_modified)
End Sub
LogCat connected to: 05157df57d72d204
--------- beginning of main
--------- beginning of system
** Activity (main) Pause, UserClosed = true **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
{"path":"/overlay.png", "mode": "overwrite"}
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
JobDone(fileupload)
RES:{"name": "overlay.png", "path_lower": "/overlay.png", "id": "id:qn6VkEYC6_gAAAAAAAAhbA", "client_modified": "2015-12-12T08:51:37Z", "server_modified": "2015-12-12T08:51:37Z", "rev": "88e411fadbd8", "size": 48945}
dbxSession=(MyMap) {name=overlay.png, path_lower=/overlay.png, id=id:qn6VkEYC6_gAAAAAAAAhbA, client_modified=2015-12-12T08:51:37Z, server_modified=2015-12-12T08:51:37Z, rev=88e411fadbd8, size=48945}
Dropbox_FileUpload: (MyMap) {name=overlay.png, path_lower=/overlay.png, id=id:qn6VkEYC6_gAAAAAAAAhbA, client_modified=2015-12-12T08:51:37Z, server_modified=2015-12-12T08:51:37Z, rev=88e411fadbd8, size=48945}
Path: /overlay.png
Rev: 88e411fadbd8
Name: overlay.png
FileSize: 48945
ClientModified: 2015-12-12T08:51:37Z
ServerModified: 2015-12-12T08:51:37Z
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
 

Attachments

  • DropboxFileUploadEx.zip
    15.3 KB · Views: 132

DonManfred

Expert
Licensed User
as the beta was very helpful

FYI (not released as yet (still working on it))

B4X:
'
' ========================
' API V2
' ========================
'
'
'users
'/get_account                 OK
'/get_current_account  OK
'/get_space_usage         OK
'/get_account_batch      MISSING

'files
'/get_metadata               OK
'/list_folder/longpoll      MISSING
'/list_folder                      OK
'/list_folder/Continue    OK
'/list_folder/get_latest_cursor  OK
'/Download                      OK
'/upload_session/start   OK
'/upload_session/append  OK
'/upload_session/finish OK
'/Upload                            OK
'/Search                             OK
'/create_folder                 OK
'/Delete                             OK
'/permanently_delete    MISSING
'/copy                                OK
'/move                               OK
'/get_thumbnail               OK
'/get_preview                   OK
'/list_revisions                  OK
'/restore                            MISSING
'

'sharing
'/get_shared_links                            OK
'/create_shared_link                        OK
'/revoke_shared_link                       OK
'/list_folders                                      OK
'/list_folders_continue                    OK
'/get_folder_metadata                    OK
'/list_folder_members                     OK
'/list_folder_members_continue   OK
'/share_folder                                    OK
'/update_folder_policy                    OK
'/unshare_folder                               OK
'/transfer_folder                               UNTESTED
'/unmount_folder                            UNTESTED
'/mount_folder                                 UNTESTED
'/add_folder_member                     OK
'/check_share_job_status               OK
'/check_job_status                           OK
'/remove_folder_member              OK
'/update_folder_member               OK
'/relinquish_folder_membership   OK

' MISSING AT ALL
' /restore
' /get_account_batch
' /ListFolderLongpoll
'
' ========================
' New in V0.92ß (12/12/15)
' sharing:
' ->get_shared_links                        
' ->create_shared_link                    
' ->revoke_shared_link                    
' ->get_folder_metadata                    
' ->list_folders                                
' ->list_folders_continue
' ->share_folder    
' ->update_folder_policy                        
' ->unshare_folder
' ->transfer_folder
' ->unmount_folder
' ->mount_folder
' ->check_share_job_status
' ->list_folder_members
' ->list_folder_members_continue
' ->remove_folder_member
' ->relinquish_folder_membership
 
Last edited:
Top