Uploading files to an ownCloud server programmatically

喜夏-厌秋 提交于 2019-11-28 10:20:27
Frank Lu

@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

Javier Gonzalez

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]];

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

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

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

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"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!