Reputation: 198
I'm working on an iOS App and I'm consuming Documentum REST services. Till now all "GET" Service part is working fine all data properly responded from server. But Now I need to do some "POST" part to upload Document files to server.
But I got stuck in Error from server.
So following code I'm using to upload Document files to server and also Provided Detailed Error Message.
Code:
(IBAction)btnPostDocumentToServer:(id)sender {
NSString *filePath=[[NSBundle mainBundle] pathForResource:@"demotpcode" ofType:@"pdf"];
NSData *pdfData = [NSData dataWithContentsOfFile:filePath];
[self postMultipart:@"http://devser1:9090/dctm-rest/repositories/Mobile/folders/0b03445d800bfa1f" fileName:@"temCodeiOS" file:pdfData progress:nil params:nil];
}
(void)postMultipart: (NSString*) url fileName: (NSString*)name file:(NSData*) fileData progress:(UIProgressView*) progressView params:(NSDictionary*) parametersDictionary {
NSDictionary *meta = @{@"properties":@{@"r_object_type": @"ecr_attachment", @"document_id": @"0903445d80210726",@"object_name": @"temCodeiOS.pdf",@"a_content_type":@"pdf",@"subject":@"new Doc from iOS Device"}}; //@{@"propreties": @{@"object_name": name}}; // You can modify this part to add more detail.
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:[[NSUserDefaults standardUserDefaults] stringForKey:@"username"] password:[[NSUserDefaults standardUserDefaults] stringForKey:@"password"]];
NSMutableURLRequest *request=[manager.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:url parameters:parametersDictionary constructingBodyWithBlock:^(id<AFMultipartFormData> formData){
[formData appendPartWithFileData:metaData name:@"metaData" fileName:@"metaData" mimeType:@"application/json"];
[formData appendPartWithFileData:fileData name:@"binary" fileName:name mimeType:@"text/plain"];
} error:nil];
NSURLSessionUploadTask *uploadTask; // Create resumable task
uploadTask = [manager uploadTaskWithStreamedRequest:request progress:^(NSProgress * _Nonnull uploadProgress) {
dispatch_async(dispatch_get_main_queue(), ^{
[progressView setProgress:uploadProgress.fractionCompleted]; //Update the progress view
});
}
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"%@ %@", response, responseObject);
}
}];
[uploadTask resume];
}
Detail ERROR:
Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo={NSUnderlyingError=0x600000056350 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: application/vnd.emc.documentum+json" UserInfo={com.alamofire.serialization.response.error.response= { URL: http://devser1:9090/dctm-rest/repositories/Mobile/folders/0b03445d800bfa1f } { status code: 400, headers { Connection = close; "Content-Type" = "application/vnd.emc.documentum+json;charset=UTF-8"; Date = "Thu, 15 Dec 2016 06:46:20 GMT"; Server = "Apache-Coyote/1.1"; "Transfer-Encoding" = Identity; } }, NSErrorFailingURLKey=http://devser1:9090/dctm-rest/repositories/Mobile/folders/0b03445d800bfa1f, com.alamofire.serialization.response.error.data=<7b227374 61747573……>, NSLocalizedDescription=Request failed: bad request (400)}
I'm using Xcode 8.1
, iOS 10.1 Simulator
and AFNETWorking 3.0
. Please Help me to understand this and guide me as I'm using AFNETWorking
First time. Thanks in advance.
Upvotes: 0
Views: 1324
Reputation: 2517
You are using wrong Content-Type value when calling Documentum REST service:
"Request failed: unacceptable content-type: application/vnd.emc.documentum+json"
I didn't use Documentum REST apart from Documetnum xCP 2.X, but in all cases application/json
was the right Content-Type (I'm no saying it'll work, just check out what your service is expecting).
Upvotes: 0