Google drive: upload a file to a specific folder

Hello,

The demo software shows only selecting folders from a CloudDemoListbox.

I only need to upload files to a specific folder. e.g. upload the file c:\MyPicture.png to the Google drive folder 'English'.

I tried this but it doesn't do anything:

Class Procedure TTMSFNCCloudGoogleDriveService.OnConnected1(Sender: TObject);
begin
var CurrentFolder: TTMSFNCCloudItem;
CurrentFolder:= TTMSFNCCloudItem.Create(Nil);
CurrentFolder.ItemType := ciFolder;
CurrentFolder.FileName := 'English';
fs_CloudGoogleDrive.Upload(CurrentFolder, 'c:\MyPicture.png');

The code above does nothing for me. Can you please help me with a working code, how to do this? Thank you.

Unfortunately the help is the shortest help I have seen in my life and moreover is not precise at all. I wouldn't call it documentation but very brief overview.
For example the very "verbose" description of "GetFolderListHierarchical" is:
"Retrieve the list of files and folders for a specific folder and add them to the GDrive list"
It fails to mention that it has 3 parameters, and also fails to mention the result type.

Also it mentions the SearchFile and SearchFolder non existent methods.

Thank you for your help!

Hi,

The Google Drive API requires a folder id to be able to upload a file to a specific folder. Only providing the folder name as the filename is unfortunately not sufficient.

You can first search for a folder (with the Search or SearchFolder call) to retrieve the folder ID and once you have that you can upload a file to a specific folder.

We are not aware of any issues with accessing SearchFile or SearchFolder with TTMSFNCCloudGoogleDrive:

Hi Bart,

Than you for the answer. SearchFile or SearchFolder were missing because I used TTMSFNCCloudService instead of TTMSFNCCloudGoogleDriveService since it was used in your demo software.

However for me only the connection seem to work. Maybe I do something in the wrong order, but as I mentioned the Dev guide doesn't help much, unfortunately.

Here I tried to list the items:

procedure TMainForm.TMSFNCCloudGoogleDrive1Connected(Sender: TObject);
begin
TMSFNCCloudGoogleDrive1.GetFolderList;
end;

procedure TMainForm.TMSFNCCloudGoogleDrive1GetFolderList(Sender: TObject;
const AFolderList: TTMSFNCCloudItems;
const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
for var I := 0 to TMSFNCCloudGoogleDrive1.GDrive.Count-1 do //HERE THE COUNT IS ALWAYS 0
Showmessage(TMSFNCCloudGoogleDrive1.GDrive.Items[i].Description);
end;

Here I tried to create a folder:

procedure TMainForm.TMSFNCCloudGoogleDrive1Connected(Sender: TObject);
begin
TMSFNCCloudGoogleDrive1.CreateFolder(nil,'A1'); // IT DIDN'T DO ANYTHING
end;
I suppose, the first parameter should be the parent, unfortunately the help only says: "CreateFolder
Create a new folder"

Here I tried to search for a folder
procedure TMainForm.TMSFNCCloudGoogleDrive1Connected(Sender: TObject);
begin
FolderList:= fs_CloudGoogleDrive.SearchFolder('English',False) ;
End;

procedure TMainForm.TMSFNCCloudGoogleDrive1Search(Sender: TObject;
const ASearchResults: TTMSFNCCloudGoogleDriveItems;
const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
ShowMessage(ASearchResults.Items[0].Description);//ARGUMENT OUT OF RANGE

end;

Thank you very much for your help!

  • GetFolderList: Please note that by default this request is handled asynchronously. You need to assign the OnGetFolderList event and access the GDrive data from there.

  • CreateFolder: This code is correct. The first parameter should indeed be the parent folder and must be nil for the root folder. We are not aware of any issues with the CreateFolder call.

  • SearchFolder: The error indicates no items are present in the ASearchResults.Items collection. This means the folder was not found. Can you please make sure that a Folder called "English" exists on the Google Drive you have authenticated and connected with?