【问题标题】:Searching for a file in Nextcloud在 Nextcloud 中搜索文件
【发布时间】:2019-02-01 21:01:48
【问题描述】:

在上传另一个文件(同名)之前,我需要检查我的 Nextcloud 中是否有文件。我还没有找到使用 curl 的任何方法(我用来上传新文件的命令)。所以,在the client API of Nextcloud搜索我找到了webDAV搜索。

我尝试在上传之前使用它来检查文件是否存在。这就是我所取得的成就:

    curl -u myUser:myPass 'https://nextcloud.customExample.com/remote.php/dav/' -X SEARCH -u myUser:myPass -H "content-Type: text/xml" --data '<?xml version="1.0" encoding="UTF-8"?>
<d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
    <d:basicsearch>
        <d:select>
            <d:prop>
                <d:displayname/>
            </d:prop>
        </d:select>
        <d:from>
            <d:scope>
                <d:href>/files/myFolder/myFile.apk</d:href>
                <d:depth>infinity</d:depth>
            </d:scope>
        </d:from>
        <d:where>
            <d:like>
                <d:prop>
                    <d:getcontenttype/>
                </d:prop>
                <d:literal>text/%</d:literal>
            </d:like>
        </d:where>
        <d:orderby>
            <d:prop>
                <oc:size/>
            </d:prop>
            <d:ascending/>
        </d:orderby>
    </d:basicsearch>
</d:searchrequest>'

执行时出现此错误:

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\NotFound</s:exception>
  <s:message>Principal with name myFolder not found</s:message>
</d:error>

如我所见,myFolder 文件夹位于 Nextcloud 的根目录中。我不知道我是否需要在它之前添加更多内容(因为我添加了“文件”)。

用户有权限,并且使用 curl 命令上传文件,该用户正在工作。

【问题讨论】:

    标签: webhooks webdav nextcloud


    【解决方案1】:

    毕竟我找到了一种更简单的方法来检查文件是否存在:

    url='http://example.com/index.html'
    if ( curl -o/dev/null -sfI "$url" ); then
      echo "URL exists"
    else
      echo "URL does not exist"
    fi
    

    如果您需要身份验证,可以在该 curl 命令中添加 --user 参数。

    我找到了here

    【讨论】:

      猜你喜欢
      • 2018-05-14
      • 1970-01-01
      • 2021-01-11
      • 2020-04-23
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      相关资源
      最近更新 更多