Upload to "File Drop" using curl from command line

Nextcloud version (eg, 10.0.2): 11
Operating system and version (eg, Ubuntu 16.04): 16.04
Apache or nginx version (eg, Apache 2.4.25): 2.4.18
PHP version (eg, 5.6): 7.0.15

Is it possible to upload to a Nextcloud “File Drop” using curl from a command line? I have tried:

curl -T fileToUpload https://nextcloud.mysite.com/s/gL8JS945tRZbGZF
curl -X PUT https://nextcloud.mysite.com/s/gL8JS945tRZbGZF --data-binary @"/tmp/test"

And I have even gone in to Chrome’s developer console, watched a sample file get uploaded and copied the curl command, which does not work, but is something like:

curl 'https://nextcloud.mysite.com/public.php/webdav/test_file.jpg' -X PUT -H 'Origin: https://nextcloud.mysite.com' -H 'Accept-Encoding: gzip, deflate, sdch, br' -H 'Accept-Language: en-US,en;q=0.8' -H 'Authorization: Basic Z0w4SlM5NDV0UlpiR1pGOg==' -H 'OCS-APIREQUEST: true' -H 'Content-Type: image/jpeg' -H 'Accept: */*' -H 'X-Requested-With: XMLHttpRequest' -H 'Content-Disposition: attachment; filename="test_file.jpg"' -H 'Connection: keep-alive' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36' -H 'Content-Length: 106717' --compressed

None of this seems to work. It seems like there should be a way to get this working that isn’t too crazy. I appreciate any help anyone can provide.

Good question. Can @rullzer or @LukasReschke help out?

Hey :slight_smile: ,
I don´t if it works on “File Drops”. But have you tried whats mentioned here
https://docs.nextcloud.com/server/10/user_manual/files/access_webdav.html#accessing-files-using-curl ?

I’m also interested in this feature. Alternatively a HTTP POST could also be used. The mentioned WebDAV has also write access…

Maybe this helps:

1 Like

It’s working as expected. Thank you!

Sorry to revive this, but wanted to share my script for this.
Same call still works fine!

I made a little bash script to send the files with something like

./cloudsend.sh ./myfile.txt https://cloud.mydomain.net/s/fLDzToZF4MLvG28

Files and folders with spaces should be quoted or escaped of course.

cloudsend.sh

Download with curl

To current folder

curl -O 'https://gist.githubusercontent.com/tavinus/93bdbc051728748787dc22a58dfe58d8/raw/cloudsend.sh' && chmod +x cloudsend.sh

To /usr/local/bin/cloudsend

Using sudo for sys install

sudo curl -o '/usr/local/bin/cloudsend' 'https://gist.githubusercontent.com/tavinus/93bdbc051728748787dc22a58dfe58d8/raw/cloudsend.sh' && sudo chmod +x /usr/local/bin/cloudsend

Help info

$ ./cloudsend.sh -h
CloudSender v0.0.7

Parameters:
  -h | --help      Print this help and exits
  -V | --version   Prints version and exits
  -k | --insecure  Uses curl with -k option (https insecure)

Use:
  ./cloudsend.sh <filepath> <folderLink>

Example:
  ./cloudsend.sh './myfile.txt' 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28'
2 Likes