Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading Files to an owncloud using curl

I have written an Application, should upload some files to several mobile devices. By now, I am using dropbox, I have an App (https://www.dropbox.com/developers), so I can upload any data to the clients Dropbox.

Now I would like to switch to owncloud because of some security concerns. I already have read this: Uploading files to an ownCloud server programatically

But unfortunately it didn't help.

I tried

curl -X PUT -u username:password "http://myserver.com/owncloud/remote.php/webdav/test" -F f=@"/tmp/test"

The file was uploaded, but there was a Problem: Some kind of Header was added to my file.

Original test-file:

test

Uploaded File:

--------------------------00c5e21306fd0b2d Content-Disposition: form-data; name="f"; filename="test" Content-Type: application/octet-stream

Dies ist ein Test.

--------------------------00c5e21306fd0b2d--

While this is really annoying on any text-Files it is a desaster on any binary files like JPGs etc, because they can't be opened any more after uploading.

That's why, I tried the other possible way, which was described:

mischka@lappy:/tmp$ curl -X PUT -u 'username:password' "http://myserver/owncloud/remote.php/webdav/test" --data-binary @"/tmp/test"
<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\BadRequest</s:exception>
  <s:message>expected filesize 19 got 0</s:message>
</d:error>

But the result was even worse!

Can anyone tell me, what I am doing wrong?

like image 917
Michèle S. Avatar asked Dec 19 '22 00:12

Michèle S.


1 Answers

-F means form upload, you should use --data-binary instead:

curl -X PUT -u username:password 
"http://myserver.com/owncloud/remote.php/webdav/test" --data-binary @"/tmp/test"
like image 168
Christian Schnidrig Avatar answered Dec 21 '22 22:12

Christian Schnidrig