TTMSFNCCloudStorageServices and how to clear storage?

Hi to all,
thank's to Pieter for his repply now there's a way to cancel an upload.
When i cancel the request how is possible to delete (remove) that item?
I mean, with

TTMSFNCCloudStorageServices.Upload(TheFolfder, TheFile) 

where
TheFolder: TTMSFNCCloudItem;
TheFile: String;

i can upload a file, with this i can cancel

uses
  FMX.TMSFNCCloudBase;

procedure TForm1.CancelRunningRequests;
var
  I: Integer;
  r: TTMSFNCCloudBaseRequest;
  rr: TTMSFNCCloudBaseRequestResult;
begin
  for I := 0 to TMSFNCCloudStorageServices1.Storage.RunningRequests.Count - 1 do
  begin
    r := TMSFNCCloudStorageServices1.Storage.RunningRequests[I];
    if r is TTMSFNCCloudBaseRequestResult then
    begin
      rr := (r as TTMSFNCCloudBaseRequestResult);
      rr.Cancel;
    end;
  end;
end;

but i can cancel the opration but how i can do to remove the file from the list ?
In other word how to clear from anythings TTMSFNCCloudStorageServices.Storage and have the
component clear as it is when the form is open.

Excuse me if i'm not so clear ......
Thank's for reply

Regards

Daniele

Hi,

Do you mean, you want to delete the item from your own list, or from the service? When cancelling an upload operation and you want to delete an item from the list, you can use

TMSFNCCloudStorageServices1.Storage.Delete()

Hi Pieter,
excuse me for long delay ....
Thank's for your reply ....
Can you check this?
When i cancel the request (rr.cancel) for, more than, 2 times i get an exception.
It's possible that this depending from server (service)?

How it's possible delete the item(s) from service?

Thank you for help

Regards
Daniele

As mentioned in the previous post, Deleting an item from the service can be done with

TMSFNCCloudStorageServices1.Storage.Delete()

Please avoid calling the running task cancel twice, because the process of cancelling takes some time.
Use the following code to check if a task is already cancelled

uses
  FMX.TMSFNCCloudBase, System.Threading;

procedure TForm32.CancelRunningRequests;
var
  I: Integer;
  r: TTMSFNCCloudBaseRequest;
  rr: TTMSFNCCloudBaseRequestResult;
begin
  for I := 0 to TMSFNCCloudStorageServices1.Storage.RunningRequests.Count - 1 do
  begin
    r := TMSFNCCloudStorageServices1.Storage.RunningRequests[I];
    if r is TTMSFNCCloudBaseRequestResult then
    begin
      rr := (r as TTMSFNCCloudBaseRequestResult);
      if not (rr.Task.Status in TTaskStatus.Canceled) then
        rr.Cancel;
    end;
  end;
end;

Hi Pieter,
as you told .... the task takes some time to be cancelled ....
The questionis ... How much time ???
In fact if i cancel, restart, cancel, restart (several time) the upload procedure something happend (i don't know what) and when the program close an exception is fired up.
Due the fact i upload only one file, this works for this condition.
In order to safe cancel the upload process we must decalre somthing like

procedure CancelRequest(Sender: TObject; const ARequestResult: TTMSFNCCloudBaseRequestResult);

and set

TMSFNCCloudStorageServices1.Storage.OnRequestCancelled:=CancelRequest;

Where the procedure is

procedure TForm1.CancelRequest(Sender: TObject; const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
  CancelledDone:=True;
end;

and the procedure used to cancel the upload will be

procedure TForm32.CancelRunningRequests;
var
  I: Integer;
  r: TTMSFNCCloudBaseRequest;
  rr: TTMSFNCCloudBaseRequestResult;
begin
  for I := 0 to TMSFNCCloudStorageServices1.Storage.RunningRequests.Count - 1 do
  begin
    r := TMSFNCCloudStorageServices1.Storage.RunningRequests[I];
    if r is TTMSFNCCloudBaseRequestResult then
    begin
      rr := (r as TTMSFNCCloudBaseRequestResult);
      if not (rr.Task.Status in TTaskStatus.Canceled) then
        rr.Cancel;
    end;
  end;
 CancelledDone:=False;
 Repeat
    Sleep(100);
    Application.ProcessMessage;
 Until CancelDone
end;

I put the "waiting" loop here because i send only one file .... for more than one file the loop must change position.
With this the user can "chages opinion" several time avoiding exception problem. In opposite the user has to wait some seconds (from 25 to more than60) to be sure that the request is, really, cancelled.
It's very problably that there's a fastest and better way to check when the request is really cancelled.

Hope this can useful for someone else.

Thank's Pieter for your support.

Regards
Daniele