Uploading files to an ownCloud server programmatically

前端 未结 6 560
鱼传尺愫
鱼传尺愫 2020-12-09 21:49

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 display

6条回答
  •  青春惊慌失措
    2020-12-09 22:19

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

提交回复
热议问题