4

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?

2 Answers 2

10

-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"
1

Upload a file you have to make a PUT request to the destiny of the file for example: http://yourOwnCloudServer/remote.php/webdav/text.txt

Here is the CURL command:

curl -X PUT -u username:password "https://yourOwnCloudServer/remote.php/webdav/text.txt" -F myfile=@"/Users/gokul/Desktop/text.txt"

You can also use --data-binary for media files.

"https://yourOwnCloudServer/remote.php/webdav/image.jpg" --data-binary @"/Users/gokul/Desktop/image.jpg"

Remember to use HTTPS or in most owncloud installations will reply

<p>The document has moved <a href="https://yourOwnCloudServer/remote.php/webdav/test">here</a>.</p>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.