阅读背景:

以编程方式将文件上载到ownCloud服务器

来源:互联网 

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.

我正在尝试设置一个Web应用程序,其中许多客户端可以通过Node.js http服务器连接,然后上载/下载文件,然后将显示在不同的显示中。我正在考虑将这些文件存储在可以集成到我的应用程序的免费云服务中。哦,我也在这个项目中使用socket.IO。

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.

Dropbox提供了一些API来执行此操作:https://www.dropbox.com/developers但我正在寻找像ownCloud这样的免费解决方案,我可以拥有更大的存储空间并拥有自己的私有服务器。

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.

有谁知道这是否可以做到?或者可以提供有关我问题的替代解决方案的任何提示?我真的很感激任何帮助,因为我对这一切都很陌生。

Thank you!!!

6 个解决方案

#1


9  

@Javier Gonzalez, To upload a file...

@Javier Gonzalez,要上传文件......

Bad option:

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

For, the uploaded file will contain the http headers.

对于,上传的文件将包含http标头。

Better option:

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

Or just use curl -T filename url to upload

或者只使用curl -T文件名网址上传

#2


6  

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

您必须通过https://yourowncloudserver.com/owncloud/remote.php/webdav/与WebDav界面进行通信

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

要上传文件,您必须向文件的命运发出PUT请求,例如:https://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命令:

curl -X PUT -u username:password "https://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

您还可以检查Objective C上的代码以检查我们使用的参数: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]];

#3


1  

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

最简单的方法是使用owncloud的webdav界面

#4


1  

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:

只需替换 , 并将其放在.bash_aliases中,您就可以上传文件:

cloud filename
cloud path filename

#5


0  

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

使用curl for windows和owncloud 8.我发现传输文件的唯一方法是使用此命令

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

Hope this helps

希望这可以帮助

#6


0  

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

上传您必须向文件命运发出PUT请求的文件,例如:https://yourOwnCloudServer/remote.php/webdav/text.txt

Here is the CURL command:

这是CURL命令:

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.

您还可以使用--data-binary作为媒体文件。

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

分享到: