【问题标题】:Nextcloud list files using APINextcloud 使用 API 列出文件
【发布时间】:2018-02-10 04:50:24
【问题描述】:

我有 NextCloud 文件存储,我想为它创建公共接口。不幸的是,我不明白如何访问它,例如通过 php (laravel) 列出文件。

也许我应该切换到 OwnCloud 软件?

您能否建议或提出任何我可以开始的例子?

【问题讨论】:

    标签: php laravel api owncloud nextcloud


    【解决方案1】:

    您可以查看一些现有的 ownCloud-client 项目以获取有关如何在服务器中实现此类请求的灵感:

    请注意,ownCloud 使用webDAV 协议来实现其一些最基本的操作(例如文件列表)。例如请求:

    $ 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>
    '
    

    得到用户演示的顶级目录列表的回复:

    <?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>
    

    【讨论】:

    • 请注意,对于 PHP,有一个 Sabre/dav 库,其中包括一个客户端助手库:sabre.io/dav/davclient。 Nextcloud 和 ownCloud 是围绕 Sabre/dav 库构建的。 Sabre 项目还包括一个围绕 PHP(丑陋的)XML 库的方便层:sabre.io/xml
    猜你喜欢
    • 2019-03-07
    • 2019-05-01
    • 1970-01-01
    • 2021-01-11
    • 2020-04-23
    • 2018-04-29
    • 2019-02-01
    • 1970-01-01
    • 2016-10-25
    相关资源
    最近更新 更多