8

I am trying to set a web application where many clients can connect through a Node.js http server and then upload/download files that will then be shown in different displays. I am thinking about having those files stored in a free cloud service that can be integrated to my app. Oh, and I am also using socket.IO in this project.

Dropbox offers some API to do this: https://www.dropbox.com/developers but I was looking into a free solution like ownCloud where I can have a larger amount of storage and also have my own private server.

Does anyone know if this can be done? or can offer any tips about alternative solutions to my problem? I would really appreciate any help with this since I am quite new to all this.

Cœur
  • 37,241
  • 25
  • 195
  • 267
tampeta
  • 541
  • 2
  • 5
  • 7

6 Answers6

13

@Javier Gonzalez, To upload a file...

Bad option:

curl -X PUT "http://yourserver.com/owncloud/remote.php/webdav/file.zip" -F myfile=@"/Users/Javi/Downloads/file.zip"

For, the uploaded file will contain the http headers.

Better option:

curl -X PUT "http://yourserver.com/owncloud/remote.php/webdav/file.zip" --data-binary @"/Users/Javi/Downloads/file.zip"

Or just use curl -T filename url to upload

Igbanam
  • 5,904
  • 5
  • 44
  • 68
Frank Lu
  • 131
  • 1
  • 2
  • 1
    HI, thanks do you have any idea how to create folder using API? – Tomas Sykora Aug 27 '15 at 10:50
  • be sure to use a valid target url without whitespaces etc. or escape them. CURL is not doing it for you. – Marcel Böttcher Sep 25 '15 at 09:15
  • 3
    @TomasSykora you can create folders in ownclod by using curl and webdav. This is how to create a folder with current date as name: curl -u user:pass -X MKCOL "http://example.org/owncloud/remote.php/webdav/$(date '+%d-%b-%Y')" see docs: https://doc.owncloud.org/server/7.0/user_manual/files/files.html#accessing-files-using-curl – serfer2 Feb 02 '16 at 11:16
  • @iGbanam How to upload $_files array ? if i upload from a form , i can not specify the path of uploading file. – augustine jenin Oct 09 '19 at 07:01
9

You have to communicate with the WebDav interface at http://yourowncloudserver.com/owncloud/remote.php/webdav/

To upload a file you have to make a PUT request to the destiny of the file for example: http://yourowncloudserver.com/owncloud/remote.php/webdav/file.zip

And add the input stream to the request to read the file.

Here is the CURL command:

curl -X PUT -u username:password "http://yourserver.com/owncloud/remote.php/webdav/file.zip" -F myfile=@"/Users/Javi/Downloads/file.zip"

You also can check our code on Objective C to check the parameters that we use: ownCloud iOS Library

NSMutableURLRequest *request = [self requestWithMethod:@"PUT" path:remoteDestination parameters:nil];
[request setTimeoutInterval:k_timeout_upload];
[request setValue:[NSString stringWithFormat:@"%lld", [UtilsFramework getSizeInBytesByPath:localSource]] forHTTPHeaderField:@"Content-Length"];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setHTTPShouldHandleCookies:NO];
//[request setHTTPBody:[NSData dataWithContentsOfFile:localSource]];

__weak __block OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request success:success failure:failure];

[operation setInputStream:[NSInputStream inputStreamWithFileAtPath:localSource]];
User
  • 14,131
  • 2
  • 40
  • 59
Javier Gonzalez
  • 480
  • 4
  • 9
  • The better answer is listed below, as stated by @Frank Lu the uploaded file will be corrupt using this method of curl if it is not sent as binary data. – Yamaha32088 Jun 16 '15 at 13:50
4

As an addition to the existing answers, I use the following function as alias:

cloud() {
  curl -X PUT -u "<username>:<password>" "https://<hostname>/remote.php/webdav/${2:-$1}" --data-binary @"./$1"
}

Just replace <username>, <password> and <hostname> and put this in your .bash_aliases and you can upload your files with:

cloud filename
cloud path filename
Johannes Stadler
  • 737
  • 12
  • 24
1

The easiest way would be to use the webdav interface of owncloud

bartv
  • 126
  • 1
  • 4
0

Using curl for windows and owncloud 8. The only way I found to transfer a file was by using this command

curl -u user:password --upload-file "c:\path to file\srcfile" "https://ocserver/owncloud/remote.php/webdav/tgtfile"

Hope this helps

0

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 "http://yourOwnCloudServer/remote.php/webdav/text.txt" -F myfile=@"/Users/gokul/Desktop/text.txt"

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

"http://yourOwnCloudServer/remote.php/webdav/image.jpg" --data-binary @"/Users/gokul/Desktop/image.jpg"
Gokul
  • 1,130
  • 13
  • 18