I've added to the CloudStorageServicesDemo app to add a Get_Link button to retrieve a shared link url to a selected existing file. Authentication works ok, I can navigate around the files in my DropBox account, but when I try to get a link or share url, it's always empty. Am I missing a step?
procedure TForm1.Get_LinkClick(Sender: TObject);
var
it: TTMSFNCCloudDropBoxItem;
link_string, share_string, fname : String ;
begin
it := TMSFNCCloudDemoListBox1.Items[TMSFNCCloudDemoListBox1.ItemIndex].DataObject as TTMSFNCCloudDropBoxItem;
fname := it.FileName ;
share_string := it.Share ;
link_string := it.Link ;
end;
Hi Bart,
Thanks for the quick response.
I've put your code into the CloudStorageServicesDemo and the GetShare event is triggered very quickly after the button click, however the share_string always comes back as empty ''.
Am I right in thinking there's nothing else I need to do to register this event?
In the meantime, I can switch to GoogleDrive and use the WebContentLink instead and everything works just fine.
Best regards,
Adam
If the event gets triggered it should be registered correctly.
Possibly there is an error in the request for retrieving the share link.
You can try to enable logging or inspect the request result by tracing the source code to find out what is going wrong.
Hi Adam,
Bart's suggestion work well for me ....
Try to do this ...
In your form declare something like Done : Boolean; LinkStr : String; and insert one label (LinkLabel)
Change procedure TForm1.Button1Click(Sender: TObject) to
procedure TForm1.Button1Click(Sender: TObject);
Var it: TTMSFNCCloudDropBoxItem;
begin
LinkStr='';
Done:=False;
TTMSFNCCloudDropBox(CloudStorage.Storage).OnGetShare := GetShare;
repeat // 1
it := CloudListbox.Items[CloudListBox.ItemIndex].DataObject as TTMSFNCCloudDropBoxItem;
TTMSFNCCloudDropBox(CloudStorage.Storage).GetShare(it);
repeat // 2
Sleep(100);
Application.ProcessMessages;
until Done ;
until LinkStr<>'';
LinkLabel.Caption:=LinkStr;
end;
With this code all work ..... and the selected item link is returned in linkStr.
Due the fact that Getshare is "asynchronous" you need to wait some time in order to finish operation.
The "waste" time is rapresented by repeat until block (2), when the link is retuned ...Done is true and all is done.
1: This repeat unitl is need because sometimes, i don't know why, at first round LinkStr is empty and on second round return the value. In this way each time you click on the button, you'll have the rigth link.
Many thanks for taking the time to reply in detail. I've implemented your suggestions but never get a non-blank link return. I had to add a iterations count to prevent the code going into an infinite loop. I'll take a look at the source code in more detail later on, but for now I'll keep working on the Google Drive option as it seems simpler and more reliable at this stage.
Thanks again,
Adam
procedure TForm1.ShareClick(Sender: TObject);
var
ci: TTMSFNCCloudItem ;
it: TTMSFNCCloudDropBoxItem;
iterations : integer ;
begin
ci := TTMSFNCCloudItem(TMSFNCCloudDemoListBox1.Items[TMSFNCCloudDemoListBox1.ItemIndex].DataObject) ;
if ( ci is TTMSFNCCloudDropBoxItem) then
begin
LinkStr := '';
iterations := 0 ;
Done := False;
TTMSFNCCloudDropBox(TMSFNCCloudStorageServices1.Storage).OnGetShare := GetShare;
repeat // 1
it := (TMSFNCCloudDemoListBox1.Items[TMSFNCCloudDemoListBox1.ItemIndex].DataObject) as TTMSFNCCloudDropBoxItem ;
TTMSFNCCloudDropBox(TMSFNCCloudStorageServices1.Storage).GetShare(it);
Hello, can you check the GetShare from Dropbox function please. I think there is a failure.
If you want the Shared Link from a file in the root, then you will get it.
Do you want to get a file from a subfolder, then you will get the link from folder in top level.
The ResultString in DoRequestGetShare() shows also as "name" the name of the top level folder.