Sabre\DAV\Exception\BadRequest: expected filesize 28558 got 0

I am trying to download a calendar as a .ics file, manipulate it and then upload the modified .ics file into the users file area. It all seems to be working OK other than uploading the .ics file which results in the following error:

Sabre\DAV\Exception\BadRequest: expected filesize 28558 got 0

0. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php - line 1130: OCA\DAV\Connector\Sabre\File->put(Resource id #8)
1. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php - line 517: Sabre\DAV\Server->updateFile('files/andy.pont...', Resource id #8, NULL)
2. [internal function] Sabre\DAV\CorePlugin->httpPut(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))
3. /var/www/nextcloud/3rdparty/sabre/event/lib/EventEmitterTrait.php - line 105: call_user_func_array(Array, Array)
4. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php - line 479: Sabre\Event\EventEmitter->emit('method PUT', Array)
5. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php - line 254: Sabre\DAV\Server->invokeMethod(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))
6. /var/www/nextcloud/apps/dav/lib/Server.php - line 287: Sabre\DAV\Server->exec()
7. /var/www/nextcloud/apps/dav/appinfo/v2/remote.php - line 35: OCA\DAV\Server->exec()
8. /var/www/nextcloud/remote.php - line 164: require_once('/var/www/nextcl...')
9. {main}

I can’t work out whether this is NextCloud being grumpy or not configured correctly or whether there is an issue with the cURL request I am making:

$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);

Anyone got any ideas?

-Andy.