I want to upload a video to a web service along with some other options. I want to upload userID , videoID and video to a web service. When downloading, all parameters other than video are sent to the web service. I checked at the end of the web service and the video does not go with the request. I am using the following code.
- (void)uploadVideoAtLocalPath:(NSString *)videoPath videoID:(NSString *)videoID userID:(NSString *)userID { NSString *strServerURL = @"www.mysite.com/user/uploadVideo"; NSURL *URL = [NSURL URLWithString:strServerURL]; AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:URL]; NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { // userID NSData *userIDData = [userID dataUsingEncoding:NSUTF8StringEncoding]; [formData appendPartWithFormData:userIDData name:@"userID"]; // videoID NSData *videoIDData = [videoID dataUsingEncoding:NSUTF8StringEncoding]; [formData appendPartWithFormData:videoIDData name:@"videoID"]; // video NSData *videoData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoPath]]; [formData appendPartWithFileData:videoData name:@"video" fileName:@"video.mov" mimeType:@"video/quicktime"]; }]; [request setURL:URL]; [request setTimeoutInterval:60.0]; [request setHTTPMethod:@"POST"]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [AFHTTPRequestOperation addAcceptableStatusCodes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(100, 500)]]; [operation setCompletionBlockWithSuccess: ^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Response String: %@", operation.responseString); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Failure: %@", error); }]; [client enqueueHTTPRequestOperation:operation]; }
Can someone tell me if I am doing this correctly? If not, can someone tell me how to upload video to a web service along with other options?
Thanks everyone!
source share