curl / Mailing Lists / curl-library / Single Mail

curl-library

Issues uploading file to NextCloud server

From: Andy Pont <andy.pont_at_sdcsystems.com>
Date: Mon, 06 Aug 2018 12:51:36 +0000

Hello, I am trying to create a PHP script to upload a single file to the WebDAV interface on a Nextcloud instance. The code I have so far is: $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $NextcloudHost . '/remote.php/webdav/files/' . $NextcloudUser . '/' . $calName); curl_setopt($curl, CURLOPT_USERPWD, $NextcloudUser . ':' . $NextcloudPass); curl_setopt($curl, CURLOPT_UPLOAD, TRUE); curl_setopt($curl, CURLOPT_INFILE, $tmpFile); curl_setopt($curl, CURLOPT_INFILESIZE, filesize($tmpFile)); curl_setopt($curl, CURLOPT_VERBOSE, TRUE); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_HEADER, FALSE); curl_exec($curl); curl_close($curl); The various parts of the CURLOPT_URL combine to be the file name to be written (or overwritten) and $tmpFile is the local file to upload. The debug output on the console when I run the script manually returns with "HTTP/1.1 400 Bad Request”. The logging in the Nextcloud instance shows the request being submitted but fails with the error “BadRequest: expected file size XXXXX got 0”. I can’t work out where to go next to determine whether this is a configuration issue with Nextcloud or me being dumb in the request I am sending. -Andy.

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2018-08-06