Cloud Storage Component
- 3 minutes to read
TdxCloudStorage is a non-visual component that allows you to interact with files stored in cloud storage. To set up the component, follow the steps below:
Select a data provider (a TdxCloudStorageProvider class descendant) for your cloud storage service.
Associate the cloud storage component with a compatible authorization agent and configure it as described in the following topic: Authorization Agents and Data Providers.
Set the component’s Connected property to True to authorize a user’s credentials and establish a connection to the cloud storage service.
How to Work with Files and Folders
The connected cloud storage component can load the online file content structure and map it to hierarchically arranged metadata containers. Use the Files property to load and navigate the content structure, where the root folder hosts all files and folders stored on a cloud storage server, except for resources within the “Trash” folder (if it is available). The cloud storage service can have a set of special folders as dedicated file categories (such as “Recent” or “Starred” folders in Google Drive). Call the Files.FetchAll procedure to populate the Files.Root and all Files.SpecialFolders properties with metadata containers mapped to the corresponding files and folders in a cloud storage.
Each metadata container (except for those that correspond to the cloud storage root and special folders) allows you to manipulate the corresponding file or folder within the online storage. For instance, you can move the “Deprecated” folder (including all its content) within the cloud storage’s root folder to “Trash”:
var
ARoot: TdxCloudStorageRoot;
I: Integer;
//...
ARoot := dxCloudStorage1.Files.Root;
// Iterates through all files at the first nesting level of the cloud storage root
for I := 0 to ARoot.Children.Count - 1 do
begin
// Checks if a cloud folder with the required name is found
if(ARoot.Children.Items[I].Name = 'Deprecated') then
begin
// Moves the found folder to the "Trash" special folder
ARoot.Children.Items[I].MoveToTrash;
break; // Exits the cycle once the target folder is trashed
end;
end;
How to Download Files
File metadata containers allow you to synchronize stored data between your application and the connected cloud storage. To download a file, you can:
Call the cloud storage component’s DownloadFile function. Pass a data stream as the AStream parameter to obtain the downloaded file’s content. The DownloadFile functions always run in the same thread from which you invoked them.
Call a metadata container’s DownloadContent procedure and handle the cloud storage component’s OnItemDownloaded event. Read the AStream parameter within the event handler to obtain the downloaded file’s content. Note that the DownloadContent procedure always runs in a separate thread.
Then, you can call the LoadFromStream and SaveToStream procedures of the recommended DevExpress controls to synchronize these file streams with your application.
How to Upload Files
Once you have created a new or edited an existing file in your application, you can upload the results to the connected cloud storage. To accomplish this, you can do the following:
Call the cloud storage component’s CreateFolder and UploadFile functions. These functions always run in the same thread from which they were invoked.
Call the CreateFolder and UploadFile procedures of a folder metadata container. Note that these procedures run asynchronously.