在 Nextcloud 中搜索文件

Searching for a file in Nextcloud

我需要在上传另一个文件(同名)之前检查我的 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 命令上传同一用户的文件。

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

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