在上传另一个文件(同名)之前,我需要检查我的 Nextcloud 中是否有文件。我还没有找到使用 curl(我用来上传新文件的命令)的任何方法。所以,在Nextcloud 的客户端 API 中搜索,我找到了 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 命令以同一用户上传文件正在工作。