Radek
Radek

Reputation: 11121

How to upload large files to a specific directory by Sabre PHP webdav client?

I would like to upload large ( bigger than 2 GB) files to Nextcloud via Sabre web dav client

Currently I have a code that lists files in specific directory so I believe that code

// Will do a PUT request with a request body
$response = $client->request('PUT', 'file.txt', "New contents");

should work. I tried these and nothing worked

//$response = $client->request('PUT', 'A87J8HRS1 - simple pdf.pdf', "Test PDF.pdf");

I thought that this code would upload to the root folder but I got

HP Fatal error:  Uncaught Sabre\HTTP\ClientException: URL rejected: Malformed input to a URL function in D:\data\projects\erp\scripts\php\vendor\sabre\http\lib\Client.php:327
Stack trace:
#0 D:\data\projects\erp\scripts\php\vendor\sabre\http\lib\Client.php(114): Sabre\HTTP\Client->doRequest()
#1 D:\data\projects\erp\scripts\php\vendor\sabre\dav\lib\DAV\Client.php(423): Sabre\HTTP\Client->send()
#2 D:\data\projects\erp\scripts\php\webDAV-listFiles.php(69): Sabre\DAV\Client->request()
#3 {main}
  thrown in D:\data\projects\erp\scripts\php\vendor\sabre\http\lib\Client.php on line 327

$response = $client->request('PUT', 'upload/A87J8HRS1.pdf', file_get_contents('A87J8HRS1 - simple pdf.pdf'));

this returns. Note that upload directory exists

:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
<s:exception>Sabre\DAV\Exception\NotFound</s:exception>
<s:message>Principal with name upload not found</s:message>

</d:error>

I tried also these but it did not work either

// $response = $client->request('PUT', '/upload/A87J8HRS1.pdf', file_get_contents('A87J8HRS1 - simple pdf.pdf'));  
// $response = $client->request('PUT', '/A87J8HRS1.pdf', file_get_contents('A87J8HRS1 - simple pdf.pdf'));

Please note that I am not connection to my Nextcloud - so I do not have any control around the webdav server. I am connection to cd.wedos.com - commercial Nextcloud.

Upvotes: 1

Views: 61

Answers (0)

Related Questions