How to assemble chunks while uploading large file using sabre webdav php client?

you are right … I updated the code and now

  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.

Do you mean wedos-auth-7518fe8d-0f5f-4c87-99a2-6exxxxxxx ? It is an userId.

I am using Sabre webdav client. So the syntax is different. The directory is created - I can see it via web UI. Of course if I use …/files/ not …/uploads/

The same applies for PUT. It works. I am able to upload. But the merge.

Below is the latest version of my code. It produces another error that I described in another post . ’ Incompatible node types error’

<?php

// installed via - composer require sabre/dav

include 'vendor/autoload.php';
use Sabre\DAV\Client;

$baseUri = '/remote.php/dav/files/wedos-auth-7518fe8d-0f5f-4c87-99a2-xxx/';
$baseUriUpload = '/remote.php/dav/uploads/wedos-auth-7518fe8d-0f5f-4c87-99a2-xxx/';

$domain = 'https://cd.wedos.com';

$settings = array(
    'baseUri' => $domain . $baseUriUpload,
    'userName' => 'xxx@gmail.com',
    'password' => 'xx'
);

$client = new Client($settings);
$filePath = 'deprese.pdf';

$uploadedFileName = 'deprese.pdf';
$uploadedFolderName = 'uploaded/';

$chunkSize = 1048576 * 5; // 1 MB * 5 = 5MB

// Create a temporary folder for chunks
$tempFolder = $baseUriUpload . uniqid('chunks_');

var_dump($tempFolder);

$response = $client->request('MKCOL', $tempFolder);

// // Read the file in chunks and upload
 $fp = fopen($filePath, 'rb');
 $chunkNumber = 0;
 $fileSize = filesize($filePath);

 while (!feof($fp)) {
     $chunk = fread($fp, $chunkSize);
     $chunkNumber++;

//     // Generate a unique filename for the chunk
        // $chunkFileName = sprintf('%010d', $chunkNumber);
        $chunkFileName =  $chunkNumber;
        $chunkPath = $tempFolder . '/' . $chunkFileName;

    // Upload the chunk
    try {
        $client->request('PUT', $chunkPath, $chunk, [
            'OC-Total-Length' => $fileSize
        ]);
        echo "Uploaded chunk $chunkNumber successfully.\n";
    } catch (Exception $e) {
        echo "Error uploading chunk $chunkNumber: " . $e->getMessage() . "\n";
        break; // Handle errors appropriately
    }

 }
 fclose($fp);

// // Assemble the final file using MOVE
// Define the source and destination paths

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

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

var_dump($response);