Skip to content

TTMSFNCCloudStorageServices

TTMSFNCCloudStorageServices is an abstract layer on top of the cloud file storage services described elsewhere in this document. It serves as a way to use the selected service in an abstract way, which means that whenever you are switching to another service, the code that was written will be 100% compatible and will behave exactly the same as the service you were originally using, ofcourse under the disclaimer that the service does not change the underlying APIs.

Usage

  • Set the Service property to the required cloud file storage service.
  • Set the Authentication.ClientID, Authentication.Secret and Authentication.CallBackURL values for the selected service.
  • To change to a difference service, simply change the Service and Authentication values.

Supported services

  • Box
  • DropBox
  • Google Drive
  • OneDrive
  • Hubic *

Note

Hubic does not support Search, Rename or Move. This is a limitation of the Hubic API service

Note

The Hubic cloud storage service has been deprecated

Properties

Property name Description
Drive A list of files and folders
CloudFiles A list of file references associated with UploadResumableFile
Service Set the cloud file storage service to use

Methods

Methods name Description
CreateFolder Create a new folder
Delete Delete a file or folder from the drive
Download Download a file from the drive
GetFolderList Retrieve the list of files and folders for the root folder or a specific folder
GetFolderListHierarchical Retrieve the list of files and folders for specific folder and add them to the Drive list
Search Search for files and folders based on a query
Upload Upload a file to the drive
Options:
Folder: Optionally provide a folder where the file is uploaded, otherwise the file is uploaded in the root folder
UploadResumableFile Upload a file to the drive in chunks. The upload is resumable and supports large files (multiple GB)
Options:
Folder: Optionally provide a folder where the file is uploaded, otherwise the file is uploaded in the root folder
MoveFile Move a file to a different folder
MoveFileToRoot Move a file to the root folder
RenameFile Rename an existing file

Sample

  • Sample using UploadResumableFile mehod and associated OnUploadResumableFile, OnUploadResumableFileFailed, OnUploadResumableFileFinished events:
public
    TMSFNCCloudStorageServices1: TTMSFNCCloudStorageServices;
    Label1: TLabel;
    ProgressBar1: TProgressBar;
    procedure TMSFNCCloudStorageServices1UploadResumableFile(Sender: TObject; ACloudFile: TTMSFNCCloudFile;
      const ARequestResult: TTMSFNCCloudBaseRequestResult);
    procedure TMSFNCCloudStorageServices1UploadResumableFileFailed(
      Sender: TObject; ACloudFile: TTMSFNCCloudFile; const ARequestResult: TTMSFNCCloudBaseRequestResult);
    procedure TMSFNCCloudStorageServices1UploadResumableFileFinished(
      Sender: TObject; ACloudFile: TTMSFNCCloudFile; const ARequestResult: TTMSFNCCloudBaseRequestResult);

procedure TForm1.Button1Click(Sender: TObject);
var
  FCloudFile: TTMSFNCCloudFile;
begin
  TMSFNCCloudStorageServices1.CloudFiles.Clear;
  FCloudFile := TMSFNCCloudStorageServices1.CloudFiles.Add;
  FCloudFile.FilePath := 'example.zip';
  TMSFNCCloudStorageServices1.UploadResumableFile(FCloudFile);
  ProgressBar1.Min := 0;
  ProgressBar1.Max := FCloudFile.GetFileSize;
  ProgressBar1.Value := 0;
end;

procedure TForm1.TMSFNCCloudStorageServices1UploadResumableFile(
  Sender: TObject; ACloudFile: TTMSFNCCloudFile; const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
  Label1.Text := 'file uploading ... ' + ACloudFile.FilePath;
  ProgressBar1.Value := ACloudFile.Position;
end;

procedure TForm1.TMSFNCCloudStorageServices1UploadResumableFileFailed(
  Sender: TObject; ACloudFile: TTMSFNCCloudFile; const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
  Label1.Text := 'file upload failed:' + ACloudFile.FilePath;
  ShowMessage(ARequestResult.ResultString);
end;

procedure TForm1.TMSFNCCloudStorageServices1UploadResumableFileFinished(
  Sender: TObject; ACloudFile: TTMSFNCCloudFile; const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
  Label1.Text := 'file upload finished! ' + ACloudFile.FilePath;
  ProgressBar1.Value := ProgressBar1.Max;
end;
  • Sample demonstrating how upload progress can be persisted:
var
  sJSON: String;

//save data
begin
  sJSON := TMSFNCCloudGoogleDrive1.CloudFiles[0].ToJSON;
end;

//load data
begin
  TMSFNCCloudGoogleDrive1.CloudFiles[0].FromJSON(sJSON);
end;