EldoS | Feel safer!

Software components for data protection, secure storage and transfer

DropBox and GogleDrive example

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#24374
Posted: 03/30/2013 03:19:10
by drazen (Standard support level)
Joined: 01/28/2013
Posts: 6

Hello,

There are no examples on how to upload/list/download on DropBox and GoogleDrive Cloud system. Also there are is no documentation about that. Can you please in few lines maybe send us how to implement this - similar to current S3/Azure demos

1. Creating component, DoOpen, doFolderRead, doObjectRead, Upload, Download

Thanks in advance!
#24377
Posted: 03/30/2013 11:12:48
by Ken Ivanov (EldoS Corp.)

Thank you for getting in touch with us.

Unfortunately, the samples are slightly behind. Yet, they are already in development at the moment, and we hope to make them available as soon as possible.

Let's start with Dropbox. First you have to authenticate to the server. During authentication, you will have to open a specific authorization URL in a browser and ask the user to complete the authentication.

Code
// Get authorization URL from Dropbox.

Storage.AppKey := AppKey;
Storage.AppSecret := AppSecret;
Storage.StartAuthorization;
AuthURL := Storage.GetAuthorizationURL();

// Open AuthURL in a browser and wait for the user to complete the authentication.

...

// Request interim access token and access secret values from Dropbox server.

Storage.RequestAccessToken();
TokenSecret := Storage.AuthTokenSecret;
Token := Storage.AuthToken;


Now you can use the four [AppKey, AppSecret, Token, TokenSecret] values to access the service. You can cache the token and the secret somewhere and use them until they expire. Once they expire, you will need to lead the user through a browser-based authentication process from scratch in order to get new token and secret.

Now that you have authenticated to the service, you can issue directory listing, read and write requests similarly to how you do this with S3 and Azure components:

Code
// General component preparation.

Storage.AppKey := AppKey;
Storage.AppSecret := AppSecret;
Storage.AuthToken := Token;
Storage.AuthTokenSecret := TokenSecret;

// Upload.

Storage.WriteObject('/my/object', true, '', Stream, nil);

// Download.

Storage.ReadObject('/my/object', Stream);


// Listing objects.

List := TElDataStorageObjectList.Create();
try
  Storage.List('/my/object', List);
finally
  FreeAndNil(List);
end;

// Acquiring an object.

var
  Obj : TElDropboxDataStorageObject;
...
Obj := FStorage.AcquireObject('/my/object');

// Listing revisions.

List := TElDataStorageObjectList.Create();
try
  FStorage.ListRevisions('/my/object', List);
finally
  FreeAndNil(List);
end;


About Google Drive: currently we only support legacy Google Docs protocol, while support for Google Drive is still in development.

Authentication to Google Docs service is done in the following way:
Code
Storage.Username := 'user@gmail.com';
Storage.Password := 'mypassword';
Storage.Authorize;
Token := Storage.AuthToken;

// Sometimes you will need to call SecondaryAuthorize to be able to access older files.
Storage.SecondaryAuthorize;
SecToken := Storage.SecondaryAuthToken;


Now you can cache the value of the Token (and optionally SecToken) and re-use them until they expire. After the expiration, you will need to call Authorize again.

Note that Google service might wish to perform additional user authorization if they decide that you are a robot. The component will throw the OnAuthCaptchaRequest event in this case and provide you with an URL to a captcha picture. You will need to show that picture to the user, ask them to enter the captcha, and return the entered value back from the event handler.

Once authenticated, all the rest of the process is similar to the other Cloud components:

Code
// General preparation.

Storage.AuthToken := Token;
Storage.SecondaryAuthToken := SecToken;
Storage.Version := gvV3
Storage.IgnoreContentSrc := true;

// Listing a folder.

Objs := TElDataStorageObjectList.Create();
try
  Storage.List(Objs);
finally
  FreeAndNil(Objs);
end;

// Downloading an object. The 'txt' option here specifies the format in which the object should be presented to the downloader (text document in this case).

Storage.ReadObject(Obj, Stream, 'txt', gdeNone);

// Uploading an object.

Storage.WriteObject('myobject', Stream, gdtDocument, 'text/plain', true, gdeNone, Handler);

Reply

Statistics

Topic viewed 1274 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!