Send Asset Video to web service - iOS

448 Views Asked by At

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?

1

There are 1 best solutions below

6
On BEST ANSWER

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.