Recent

Author Topic: Help needed on how to do a NextCloud client...  (Read 626 times)

cdbc

  • Hero Member
  • *****
  • Posts: 2869
    • http://www.cdbc.dk
Help needed on how to do a NextCloud client...
« on: July 09, 2026, 10:13:28 am »
Hi Everybody :)
So, I've been running -IceWM- on my old lappy for the last 6 months or so, it works a treat, but alas, the normal 'NextCloud'-client that I run on KDE6 won't run on IceWM... :(
So, I'd like to ask for help, inspiration, pointers and maybe even code-snippets, to get the ball rolling, wrt. me building a personal client for the Nextcloud...
I'm using the cloud as fileserver, for now...
TIA
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Zvoni

  • Hero Member
  • *****
  • Posts: 3441
Re: Help needed on how to do a NextCloud client...
« Reply #1 on: July 09, 2026, 10:53:32 am »
Well, you could always look on GitHub at NC's own Client, written in c++, to get a starting point
https://github.com/nextcloud/desktop
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

paweld

  • Hero Member
  • *****
  • Posts: 1678
Re: Help needed on how to do a NextCloud client...
« Reply #2 on: July 09, 2026, 11:10:44 am »
In my opinion, the easiest way is to use WebDAV - here's a simple example of how to upload a file to the cloud:
Code: Pascal  [Select][+][-]
  1. uses
  2.   fphttpclient, opensslsockets,
  3.   base64;
  4.  
  5. procedure TForm1.Button1Click(Sender: TObject);
  6. const
  7.   url = 'https://my.next.cloud.instance.pl/remote.php/dav/files/user';
  8.   directory = 'Public';
  9.   login = 'user';
  10.   pass = 'userpassword';
  11. var
  12.   hc: TFPHttpClient;
  13. begin
  14.   if not OpenDialog1.Execute then
  15.     exit;
  16.   hc := TFPHttpClient.Create(nil);
  17.   hc.AllowRedirect := True;
  18.   hc.RequestHeaders.Insert(0, 'Authorization: Basic ' + EncodeStringBase64(login + ':' + pass)); //auth
  19.   hc.RequestBody := TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
  20.   hc.Put(url + '/' + directory + '/' + ExtractFileName(OpenDialog1.FileName)); //upload file
  21.   if hc.ResponseStatusCode div 100 = 2 then
  22.     ShowMessage(Format('File [%s] uploaded to WebDAV', [ExtractFileName(OpenDialog1.FileName)]))
  23.   else
  24.     ShowMessage(Format('Upload error: [%d] %s', [hc.ResponseStatusCode, hc.ResponseStatusText]));
  25.   hc.RequestBody.Free;
  26.   hc.Free;
  27. end;    
Best regards / Pozdrawiam
paweld

PierceNg

  • Sr. Member
  • ****
  • Posts: 437
    • SamadhiWeb
Re: Help needed on how to do a NextCloud client...
« Reply #3 on: July 09, 2026, 11:19:33 am »
NextCloud offers OpenAPI spec: https://docs.nextcloud.com/server/latest/developer_manual/_static/openapi.html#/. Clicking the 'export' button on that page downloads a JSON file about 2MB in size that presumably contains the full API.

You could use mORMot's OpenAPI code generator to generate Pascal client code for said API. See https://forum.lazarus.freepascal.org/index.php/topic,68444.0.html.

cdbc

  • Hero Member
  • *****
  • Posts: 2869
    • http://www.cdbc.dk
Re: Help needed on how to do a NextCloud client...
« Reply #4 on: July 09, 2026, 04:12:07 pm »
Wow guys \o/
Thanks a whole lot, that's great stuff, very much appreciated  8)
Methinks me got som' studying todo  :D
Will prolly return here with follow-up questions...  ;D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

paweld

  • Hero Member
  • *****
  • Posts: 1678
Re: Help needed on how to do a NextCloud client...
« Reply #5 on: July 09, 2026, 06:59:04 pm »
Here is a more detailed example: upload a file, delete a file, get a list of directories and files
Best regards / Pozdrawiam
paweld

cdbc

  • Hero Member
  • *****
  • Posts: 2869
    • http://www.cdbc.dk
Re: Help needed on how to do a NextCloud client...
« Reply #6 on: July 09, 2026, 09:47:25 pm »
Hi Pawel
Thanks a lot mate, I have got your first example working and was scouring the API online for info on fetching dir/files-list, gettting a file downloaded and deleting a file... Now I'll be perusing your bigger example \o/
When "Put" uploads the file, I assume the same goes for "Get", with roughly the same params, when downloading ?!?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

paweld

  • Hero Member
  • *****
  • Posts: 1678
Re: Help needed on how to do a NextCloud client...
« Reply #7 on: July 09, 2026, 10:06:31 pm »
Quote from: cdbc
When "Put" uploads the file, I assume the same goes for "Get", with roughly the same params, when downloading ?!?
Yes.

A description of other operations on directories and files is available, for example, here: https://http.dev/webdav
Best regards / Pozdrawiam
paweld

paweld

  • Hero Member
  • *****
  • Posts: 1678
Re: Help needed on how to do a NextCloud client...
« Reply #8 on: July 11, 2026, 01:45:29 pm »
And just for your information: the Indy package includes the TIdWebDAV component
Best regards / Pozdrawiam
paweld

cdbc

  • Hero Member
  • *****
  • Posts: 2869
    • http://www.cdbc.dk
Re: Help needed on how to do a NextCloud client...
« Reply #9 on: July 11, 2026, 05:55:05 pm »
Hi Pawel
Thanks mate =^
I'm fiddling with your example project, but somehow I don't get the names of items shown in view, have a looksee in screenshot below...
What am I missing...?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

paweld

  • Hero Member
  • *****
  • Posts: 1678
Re: Help needed on how to do a NextCloud client...
« Reply #10 on: July 11, 2026, 06:47:28 pm »
Hi Benny,
Without the XML, it's hard to say what's causing this, but take a look at the attachment - I've expanded the project a bit and added logic to retrieve the name from the path if it's not included in the “displayname” tag.
Best regards / Pozdrawiam
paweld

cdbc

  • Hero Member
  • *****
  • Posts: 2869
    • http://www.cdbc.dk
Re: Help needed on how to do a NextCloud client...
« Reply #11 on: July 11, 2026, 08:38:38 pm »
Hi Pawel
Cool, that did the trick, now I'm diving in for dissecting the new goodies  :D
Thanks a lot mate =^
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

cdbc

  • Hero Member
  • *****
  • Posts: 2869
    • http://www.cdbc.dk
Re: Help needed on how to do a NextCloud client...
« Reply #12 on: July 12, 2026, 12:15:15 pm »
Hi
@PawelD: Your code is brilliant mate thank you. And you're completely right, webDAV is the right tool for the job \o/
I did download the full openAPI from Nextcloud and mORMot2 additionally, then used 'mopenapi' to generate the pascal class to handle the API -- Pheeewww it's BIG. That API is the completely _wrong_ tool for the job...!
I've attached it for the 'nosy' ones among youse... The json-file is way to big for the forum...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

 

TinyPortal © 2005-2018