Hi,
I'm new with ownCloud, sorry if my post does not mach with selected category.
I'm developing an iOS app that can login and upload some media file to my ownCloud server.
The server is good, I can login, share and upload files, same with Android.
But with iOS app, although I can do authentication successfully, when I tried to upload audio file (ex: wav), I always receive error 405, which means don't have permission.
Please help me if you have any comment.
Thank you very much.
Here is my demo source code
1. For authentication
static NSString *BASE_URL = @"https://xxx.xxx.xxx/";
(OCCommunication *)ocCommunication
{
if (!_ocCommunication) {
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:k_session_name];
configuration.HTTPMaximumConnectionsPerHost = 1;
configuration.requestCachePolicy = NSURLRequestUseProtocolCachePolicy;
configuration.timeoutIntervalForRequest = k_timeout_upload;
configuration.sessionSendsLaunchEvents = YES;
[configuration setAllowsCellularAccess:YES];
AFURLSessionManager *uploadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
[uploadSessionManager.operationQueue setMaxConcurrentOperationCount:1];
[uploadSessionManager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition (NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential) {
return NSURLSessionAuthChallengePerformDefaultHandling;
}];NSURLSessionConfiguration *configurationDownload = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:k_download_session_name]; configurationDownload.HTTPMaximumConnectionsPerHost = 1; configurationDownload.requestCachePolicy = NSURLRequestUseProtocolCachePolicy; configurationDownload.timeoutIntervalForRequest = k_timeout_upload; configurationDownload.sessionSendsLaunchEvents = YES; [configurationDownload setAllowsCellularAccess:YES]; AFURLSessionManager *downloadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configurationDownload]; [downloadSessionManager.operationQueue setMaxConcurrentOperationCount:1]; [downloadSessionManager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition (NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential) { return NSURLSessionAuthChallengePerformDefaultHandling; }]; NSURLSessionConfiguration *networkConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; networkConfiguration.HTTPShouldUsePipelining = YES; networkConfiguration.HTTPMaximumConnectionsPerHost = 1; networkConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData; AFURLSessionManager *networkSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:networkConfiguration]; [networkSessionManager.operationQueue setMaxConcurrentOperationCount:1]; networkSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer]; _ocCommunication = [[OCCommunication alloc] initWithUploadSessionManager:uploadSessionManager andDownloadSessionManager:downloadSessionManager andNetworkSessionManager:networkSessionManager]; [_ocCommunication setIsCookiesAvailable:YES]; [_ocCommunication setUserAgent:self.userAgent];
OCCredentialsDto *ocCredentialsDto = [[OCCredentialsDto alloc] init]; ocCredentialsDto.userName = @"xxx"; ocCredentialsDto.accessToken = @"xxx"; ocCredentialsDto.baseURL = BASE_URL; ocCredentialsDto.authenticationMethod = AuthenticationMethodBASIC_HTTP_AUTH; [_ocCommunication setCredentials:ocCredentialsDto]; } return _ocCommunication;
}
- (NSString *)userAgent {
if (!_userAgent) {
_userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
}
return _userAgent;
}
- Upload media file
- (void)uploadFile:(NSString *)filePath toServer:(NSString *)serverPath
{
NSString *uploadPath = [[NSString stringWithFormat:@"%@%@", BASE_URL, serverPath] stringByRemovingPercentEncoding];
[self.ocCommunication uploadFileSession:filePath
toDestiny:uploadPath
onCommunication:self.ocCommunication
progress:^(NSProgress *progress) {
}
successRequest:^(NSURLResponse *response, NSString *redirectedServer) {
}
failureRequest:^(NSURLResponse *response, NSString *redirectedServer, NSError *error) {
}
failureBeforeRequest:^(NSError *error) {
}];
}
- (void)uploadFile:(NSString *)filePath toServer:(NSString *)serverPath