TdxCloudStorage.UploadFile(TdxCloudStorageFolder,string,TdxCloudStorageFileProgressCallback,Boolean) Method
Uploads a locally stored file to the cloud storage.
Declaration
function UploadFile(AParent: TdxCloudStorageFolder; const AFileName: string; AProgressCallback: TdxCloudStorageFileProgressCallback = nil; AOverwriteIfExists: Boolean = True): TdxCloudStorageFile; overload;
Parameters
Name | Type | Description |
---|---|---|
AParent | TdxCloudStorageFolder | A cloud folder metadata container that corresponds to the target folder. |
AFileName | string | The path to a file on the local machine. |
AProgressCallback | TdxCloudStorageFileProgressCallback | A callback procedure that tracks file upload progress. |
AOverwriteIfExists | Boolean | If True, the function overwrites the matching file in the cloud storage; otherwise, the function just returns the metadata container of an existing file. |
Returns
Type | Description |
---|---|
TdxCloudStorageFile | A cloud file metadata container that corresponds to the uploaded file. |
Remarks
The following code example uploads the Image.jpg file in the application’s Images folder to the corresponding folder in a connected cloud storage.
var
ARoot: TdxCloudStorageRoot;
AImagesFolder: TdxCloudStorageFolder;
I: Integer;
AFound: Boolean;
//...
AFound := False;
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 "Images" name is found
if(ARoot.Children.Items[I].Name = 'Images') then
begin
AFound := True;
// Uploads the Image.jpg file to the Images folder on the cloud storage server
dxCloudStorage1.UploadFile(ARoot.Children.Items[I], 'Images/Image.jpg');
break; // Exits the cycle once the file is uploaded
end;
end;
if (not AFound) then // If the "Images" folder is not found
begin
// Creates a new folder named "Images" in the storage root
AImagesFolder := dxCloudStorage1.CreateFolder(dxCloudStorage1.Files.Root, 'Images');
if (AImagesFolder <> nil) then
dxCloudStorage1.UploadFile(AImagesFolder, 'Images/Image.jpg');
end;
You can also implement a callback procedure and pass it as the AProgressCallback optional parameter to track file upload progress. Refer to the TdxCloudStorageFileProgressCallback procedural type description for details. The UploadFile procedure overwrites a file with the matching name in a destination folder. You can pass False as the AOverwriteIfExists optional parameter to preserve a file with the matching name and return the metadata container corresponding to the preserved file.
Note
The UploadFile function always runs in the same thread from which it is called.