I am writing a command line script to put events into a calendar using curl. I managed to get this working by first creating a temporary local calendar file and then uploading this file to the server using these commands:
$command > $localfile
curl -T "$localfile" $url
This works perfectly, but I’d like to get rid of the local file. I’m looking for a way to pipe the output of $command straight to curl. Something like this:
$command | curl -T - $url
According to curl’s manual, the option T - should be what is required: read from stdin instead from a file. But if I use that option, I get this response:
<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
<s:exception>Sabre\DAV\Exception\Conflict</s:exception>
<s:message>PUT is not allowed on non-files.</s:message>
</d:error>
I’m not very experienced with cURL but -T (--upload-file) will try to upload the file. You’ll probably need to use --data or other parameters like --data-raw.
I’m afraid I cannot help you in detail, but maybe this solves it or is at least a hint in the right direction.
As this is more a cURL/Linux and not a specific Nextcloud question, you might get better answers on sites like stackoverflow.
I was thinking this could also be an issue specific to NC, maybe NC needs a special parameter or some option in the server’s settings to allow this kind of upload.
Try this one: $command | curl --data @- $url
If it doesn’t work try --data-raw or --data-urlencode parameters instead.
EDIT: Or maybe $command | curl -T . $url
And of course a very simple workaround if you want to get rid of the local file (but using it temporarily) would look like this: curl -T "$localfile" $url && rm $localfile
Regard the “-” between “<<” and “EOF”: that dash is required, if you use tabs to format your script to increase readability. It removes any tabs from the data stream.
Somehow, this kind of upload behaves completely different than the option “-T” plus reading from standard input as described in the manual. If someone knows why a HERE document works but the option “-T” does not work, I’d be happy to learn!