Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading files to an ownCloud server programmatically

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.

like image 516
tampeta Avatar asked Jul 15 '14 12:07

tampeta


2 Answers

@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

like image 178
Frank Lu Avatar answered Oct 02 '22 22:10

Frank Lu


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]];
like image 39
Javier Gonzalez Avatar answered Oct 03 '22 00:10

Javier Gonzalez