Search code examples
phpwebdavsabredav

Solution for "Incompatible node types error" when moving files via webDav


I am trying to upload large file via sabre ftp client. I was following the documentation Chunked file upload — Nextcloud latest Developer Manual latest documentation

Now I am getting this error

<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\BadRequest</s:exception>
  <s:message>Incompatible node types</s:message>
</d:error>

The code that generates this error is

$sourcePath = $tempFolder . '/.file';
$destinationPath = $baseUri . $uploadedFolderName . $uploadedFileName;

var_dump($destinationPath);
//  "/remote.php/dav/files/wedos-auth-7518fe8d-0f5f-4c87-99a2-xxx/uploaded/deprese.pdf"

var_dump($sourcePath);

//  "/remote.php/dav/uploads/wedos-auth-7518fe8d-0f5f-4c87-99a2-xxx/chunks_674d6d3f46a9f/.file"

// Send the MOVE request
$response = $client->request('MOVE', $tempFolder, null, [
    'Destination' => $destinationPath,
    'OC-Total-Length' => $fileSize
]);

someone can help to make it work?

  1. I am able to create temp directory
  2. I am able to upload chunks
    • if I upload to .../files/... I can see them.
    • if I upload to .../upload/... I cant see them but I would say they were uploaded. There was no error
  3. So the only step for uploading a large file is to merge all the chunks.

Solution

  • For the final step of a chunked upload, you need to send a MOVE request from the pseudo-file:

    <server>/remote.php/dav/uploads/<user>/<folder>/.file

    to the destination file:

    <server>/remote.php/dav/files/<user>/<folder>/<file>

    So, in your case, the correct way to do the request is:

    $sourcePath = $tempFolder . '/.file';
    $destinationPath = $baseUri . $uploadedFolderName . $uploadedFileName;
    
    $response = $client->request('MOVE', $sourcePath, null, [
        'Destination' => $destinationPath,
        'OC-Total-Length' => $fileSize
    ]);