FMX Cloud Upload

I select a folder in my TreeView and click on the Send button to transfer the file to my DropBox.

This seems to work fine. However, if I accidentally click on an existing file in this folder and press the Send button, the existing file is deleted but the name remains as a folder. The new file is then transferred into this folder that was a file.



E.g.



1:

Folder1

    File1

    File2



2:

I create File3, select Folder1 and press Send button. I get



Folder1

    File1

    File2

    File3



3:

Now I create File4 and accidentally select File1. When I press the send button I get:



Folder1

    File1

        File4

    File2

    File3



File1 has changed from a file to a Folder.

I would have expected the upload mechanism to detect I had selected a file and uploaded to the current Folder which in this case is Folder1.



Any comments?



Or maybe we just need to protect ourselves to ensure we have selected a Folder:



    if Assigned(TreeView1.Selected) then

    begin

      ci := TTMSFMXCloudItem(TTMSFMXCloudTreeViewItem(TreeView1.Selected).DataObject);



      if ci.ItemType = ciFolder then

      begin

        nci := MyStorage.Upload(ci, fn);



        if Assigned(nci) then

        begin

          TreeView1.Clear;

          MyStorage.GetDriveInfo;

          MyStorage.FillTreeView(TreeView1);

        end;

      end

      else

      begin

        ShowMessage ('Select a Folder');

      end;

    end;

Hi,


You can indeed check if the selected item is a folder before starting the upload.
Additionally you can also get the ParentFolder of the item if the ItemType is ciFile and automatically upload the file to that folder.

Yes, that's actually a better solution:



      ci := TTMSFMXCloudItem(TTMSFMXCloudTreeViewItem(TreeView1.Selected).DataObject);



      if (ci.ItemType = ciFile) then

      begin

        if (ci.ParentFolder <> nil) then

          ci := ci.ParentFolder

        else

          ci := nil;

      end;



      nci := MyStorage.Upload(ci, fn);



      if Assigned(nci) then

      begin

        TreeView1.Clear;

        MyStorage.GetDriveInfo;

        MyStorage.FillTreeView(TreeView1);

      end;



The one thing I now cannot seem to do is upload a file to the top level if there are no other files at the top level.

I can solve it by having another "Send" button which will force an upload to the top, but can't see any other way. Somehow you need to deselect the entry in the Tree.



Is this fundamental?



Graham

It is just a shortcoming in the demo itself. The component itself can perfectly handle uploading files in the root folder. We have changed the demo to not select a node by default, so you can do it with the demo now as well as long as you don't select an existing folder.