restcurlwebdavnextcloud

Error uploadig a file to NextCloud via API


I'm trying to upload a file:

curl -X PUT -u "my_username:pass123" "https://nextcloud.my_domain.com/remote.php/webdav/Shared/dir1/" --data-binary @"/Users/user1/test1.png"

Error:

  <?xml version="1.0" encoding="utf-8"?>
  <d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
    <s:exception>Sabre\DAV\Exception\Conflict</s:exception>
    <s:message>PUT is not allowed on non-files.</s:message>
  </d:error>

Why?

The credentials I'm using are the ones I use for login in the browser.


Solution

  • The PUT request needs to refer to the actual file you want to create, right now you are pointing to a directory.

    So instead of:

    https://nextcloud.my_domain.com/remote.php/webdav/Shared/dir1/
    

    Use:

    https://nextcloud.my_domain.com/remote.php/webdav/Shared/dir1/test1.png