Nextcloud list files using API

7.2k views Asked by At

I have NextCloud file storage and I want to create public interface for it. Unfortunately I do not understand how can access it and for example list files through php (laravel).

Maybe I should switch to OwnCloud software?

Could you please advise or bring up any example I could start from?

1

There are 1 answers

1
Alfageme On BEST ANSWER

You can check out some existing ownCloud-client projects for inspiration on how to implement that kind of requests in the server:

Note that ownCloud uses the webDAV protocol to implement some of its most basic operations (such as file listing). e.g. the request:

$ curl -H 'Cookie:$SESSION' -X PROPFIND 'https://demo.owncloud.com/remote.php/dav/files/demo/' --data-binary \
'<?xml version="1.0" ?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
  <d:prop>
    <d:resourcetype />
  </d:prop>
</d:propfind>
'

Gets replied with the top-level directory listing of the user demo:

<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:oc="http://owncloud.org/ns">
  <d:response>
    <d:href>/remote.php/dav/files/demo/</d:href>
    <d:propstat>
      <d:prop>
        <d:resourcetype>
          <d:collection/>
        </d:resourcetype>
      </d:prop>
      <d:status>HTTP/1.1 200 OK</d:status>
    </d:propstat>
  </d:response>
  <d:response>
    <d:href>/remote.php/dav/files/demo/Documents/</d:href>
    <d:propstat>
      <d:prop>
        <d:resourcetype>
          <d:collection/>
        </d:resourcetype>
      </d:prop>
      <d:status>HTTP/1.1 200 OK</d:status>
    </d:propstat>
  </d:response>
  <d:response>
    <d:href>/remote.php/dav/files/demo/Photos/</d:href>
    <d:propstat>
      <d:prop>
        <d:resourcetype>
          <d:collection/>
        </d:resourcetype>
      </d:prop>
      <d:status>HTTP/1.1 200 OK</d:status>
    </d:propstat>
  </d:response>
  <d:response>
    <d:href>/remote.php/dav/files/demo/ownCloud%20Manual.pdf</d:href>
    <d:propstat>
      <d:prop>
        <d:resourcetype/>
      </d:prop>
      <d:status>HTTP/1.1 200 OK</d:status>
    </d:propstat>
  </d:response>
</d:multistatus>