DropBox for Grails

Hiten Pratap Singh edited this page Jul 18, 2014 · 4 revisions
Clone this wiki locally

# DropBox Plugin for Grails


It's a plugin for Grails that aims to integrate all Dropbox functionalities like add a file/folder or delete a file/folder etc all from inside Grails application using this plugin.

# Features


This plugins provides following main features-

  • Allow a user to generate an access token from within the code.
  • Allow to add a file/folder.
  • Allow to upload a file in chunk and tracks its parts.
  • Allow to delete a file.
  • Allow to move a file from one folder to other. and all other provided by Dropbox.

# Usage


1. First of all user needs to add these properties into config.groovy file

  • grails.plugins.dropBox.appKey="Your Dropbox App Key"
  • grails.plugins.dropBox.appSecret="Your Dropbox App secret"

Above App key and App secret can be get by create an application at Dropbox by this url Create an app


2. Next user need an access token in order to use any Dropbox service like create a file etc. For this task there is a AccessTokenService is available in plugin and access token can be generated by this service only by follow three simple steps:

  • First of all get an authUrl by executing this accessTokenService.getAuthUrl() and it will gives a url.
  • Next user will need to redirect to above authUrl from Step 1 and then DropBox will give you a code.
  • And last step is to get an access token and it can be easily get by executing accessTokenService.getAccessToken(code). Here you need to pass code to it got by step 2 and then this method will give an access token. Save it anywhere like database or somewhere else for further use.

3. Next part will give you details about using various DropBox services by using access token got from above part.

  • Account Info - This service will give account details like uid and display name of any Dropbox user. For get account info there is a service called DropBoxService. So for get account info simple execute dropBoxService.accountInfo(accessToken). Pass access token to it and it will give you various details about DropBox user.

  • File Upload - This service will allow you to upload file to Dropbox. To do so there is a service called DropBoxService . So to upload any file to Dropbox you will need to specify four things i.e. root, source file's byte array, destination path and access token. You can get access token from previous step and for root you can use dropbox or sandbox. source file's byte array is the array contains bytes of the file which you want to upload to dropbox and destination path is path on dropbox for file to upload to. There is one thing to note that destination path must not point to a folder. Now just call dropBoxService.dropBoxFileUpload() to upload any file to Dropbox.

  • Retrieves file and folder metadata - To get meta data information about any file or folder at Dropbox you just need three things i.e. root, path and access token. root is same dropbox or sandbox, path is any folder/file at dropbox for which you want to retrieve info and access token can be get from previous step. Now to do so there is service called DropBoxService and you just have to invoke its getObjectMetaData() method.

  • Create New Folder - To create a new folder at Dropbox is pretty easy. All you need is just three things i.e. root, path and access token. root and access token are same as previous. Path can be anything to the new folder to create relative to root. To do so there is a service called DropBoxService and you just have to invoke its createNewFolder() method.

  • Copies a file/folder to a new location - To copy a file/folder to new location at Dropbox, you just need to have four things i.e. root, access token, fromPath and toPath. Actually root and access token are just same as previous steps. fromPath is path of file/folder to copy from and toPath is path of new location to copy file/folder to. To do so there is a service called DropBoxService and you just have to invoke its copyOps() method.

  • Moves a file/folder to a new location - To move a file/folder to new location at Dropbox, you just need to have four things i.e. root, access token, fromPath and toPath. Actually root and access token are just same as previous steps. fromPath is path of file/folder to move from and toPath is path of new location to move file/folder to. To do so there is a service called DropBoxService and you just have to invoke its moveOps() method.

  • Deletes a file/folder - To delete a file/folder at Dropbox is pretty easy. All you need is just three things i.e. root, path and access token. root and access token are same as previous. Path can be anything to the existing file/folder relative to root. To do so there is a service called DropBoxService and you just have to invoke its deleteFileOps() method.