1

I am trying to send video in assets library to web service with parameter video but how is it possible to do ?

I got the NSURL as the following : assets-library://asset/asset.MOV?id=What-ever-0000-000&ext=MOV

I am using AFNetworking to send the post request and here is my code :

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]];
[manager.requestSerializer setValue:@"no-cache" forHTTPHeaderField:@"Catch-Control"];
NSDictionary *parameters = @{@"video": myurl};
[manager POST:@"this is my service link" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

Do I need to convert the NSURL to another representation so I can submit it? I have no idea?

Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
AaoIi
  • 8,288
  • 6
  • 45
  • 87

1 Answers1

1

You can post video to server like this.

AFHTTPRequestOperation *op = [theManager POST:urlString
                                parameters:theParameters
                 constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
                                    {
                                        [formData appendPartWithFileURL:postedVideoURL name:@"media" fileName:@"FinalMovie.mp4" mimeType:@"mp4" error:nil];
                                        [formData appendPartWithFileData:imgData name:@"video_thumb" fileName:@"png" mimeType:@"image/jpeg"];
                                    }
                                success:^(AFHTTPRequestOperation *operation, id responseObject)
                                    {}
                                   failure:^(AFHTTPRequestOperation *operation, NSError *error)
                                    {}]; 
[op start];

Create theManager object like this.

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

Hope this helps.

Bharat Nakum
  • 647
  • 6
  • 18
  • Can you specify your code, what is theManager or whatever ? define it before so i may possibly know what am i supposed to do ? you are using AFHTTPRequestOperation and i am using AFHTTPRequestOperationManager. Thank you @Roy Nakum !! – AaoIi Aug 13 '15 at 11:20
  • postedVideoURL is what exactly ? my parameter ? my nsurl ? or the returned data from the server ? @Roy Nakum ! – AaoIi Aug 13 '15 at 11:29
  • postedVideoURL is URL for my video that I want to upload to the server. – Bharat Nakum Aug 13 '15 at 11:30
  • The server is returning nil : JSON: (null) mm ! by sending the NSURL its actually sending the actual video right ? Thanks ! – AaoIi Aug 13 '15 at 11:31
  • I'm sending it as : `NSDictionary *parameters = @{@"video": myurl};` nothing wrong ! – AaoIi Aug 13 '15 at 11:38
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/86879/discussion-between-roy-nakum-and-aaoii). – Bharat Nakum Aug 13 '15 at 11:39